[concurrency-interest] AtomicReference.updateAndGet() mandatory updating

Doug Lea dl at cs.oswego.edu
Fri May 26 08:46:32 EDT 2017

On 05/26/2017 04:44 AM, Andrew Haley wrote:

>> a compareAndSet has the memory semantics of a volatile
>> write regardless of whether or not the write occurred. 
> That property of compareAndSet is very ugly, and is a pain to
> implement. Most of the CAS instructions I know about don't have such
> a property, and making it work requires either an unconditional full
> fence after every CAS or a conditional one if it fails.  Either way
> sucks mightily and is unlikely to be useful except in the most
> pathological cases.

Initially (in Java5) requiring it has led to some questionable reliance.
 So we cannot change it. But there's not much motivation to do so anyway:
As implied by Nathan Reynolds, encountering some (local) fence overhead
on CAS failure typically reduces contention and may improve throughput.


More information about the Concurrency-interest mailing list