ConcurrentHashMap/ConcurrentMap/Map.compute
Doug Lea
dl at cs.oswego.edu
Fri Dec 7 06:51:50 PST 2012
On 12/07/12 09:22, Brian Goetz wrote:
> The following default implementation *is* atomic because putIfAbsent is already
> atomic in CM:
>
> computeIfAbsent(K key, K->V fn) {
> if (!containsKey(key))
> putIfAbsent(key, fn.apply(key));
> }
>
Thanks for prod to try recasting this wrt *scopes* of atomicity.
Which, with some further re-work propagates up to plain Map versions
as well without need for re-abstraction. I'll try it out and post an
update. Basic idea: defaults for function-accepting Map methods are solely
in terms of the 4 CM methods, which are in turn non-atomic for non-CM.
But implementations can if desired/possible, further widen
atomicity scope to include the function call.
-Doug
More information about the lambda-libs-spec-observers
mailing list