[concurrency-interest] ConcurrentHashMapV8

Zhong Yu zhong.j.yu at gmail.com
Tue Aug 30 00:42:41 EDT 2011


On Mon, Aug 29, 2011 at 6:43 PM, Doug Lea <dl at cs.oswego.edu> wrote:

> Well, in CHMV8. it won't deadlock, but instead gets into
> an infinite loop (a form livelock), which makes it a more
> marginal call whether to place a check that is not cheap
> along a common path. But I'm tentatively planning to put it
> in to next update anyway.

If the caller has to worry about these things, it makes
computerIfAbsent(key, func) much less useful.

Usually this method is needed when the computation is expensive or has
side effects. (In many code structures the caller can't be sure about
the details of `func.map()`, therefore the worst is assumed.)

Requiring that the computation is transparent to the caller, must be
inexpensive and must not write to the map, will turn away majority of
potential users. This makes the method much less valuable than it
first appears.

In case the requirement can be met, `func.map()` can be cheaply and
safely invoked anyway, the saving by `computeIfAbsent()` is very
little, except in some extreme use cases (and these people can
probably afford their own customized implementations).

The requirement that the computation must not write to entries of
different keys seems especially hard to cope with. For example, if a
map is used as a cache; when computing value for `k1`, it might be
reasonable to disallow recursion on `k1`; however, it will be very odd
and inconvenient to disallow `cache.get( k2, #{ load(k2) } )` when
computing value for `k1`.

Zhong Yu


More information about the Concurrency-interest mailing list