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

Doug Lea dl at cs.oswego.edu
Thu May 25 06:39:22 EDT 2017

On 05/25/2017 06:16 AM, Andrew Haley wrote:
> On 25/05/17 09:16, Gil Tene wrote:
>>> On May 25, 2017, at 12:35 AM, Alex Otenko
>>> <oleksandr.otenko at gmail.com> wrote:
>>> This is a bad idea.
>>> Now there is no guarantee that the synchronizes-with edge
>>> exists.
>> The current Java 9 specification (in the JavaDoc) of
>> AtomicReference.updateAndGet() doesn't say there is such an edge
>> (the Java 8 one did, but the current Java 9 one doesn't).
> Ah, I see:
> "compareAndSet and all other read-and-update operations such as
> getAndIncrement have the memory effects of both reading and writing
> volatile variables. " seems to have gone.  

Thanks for pointing this out!
The "...and all other read-and-update operations" clause
inadvertently disappeared while meshing j.u.c.atomic specs
with jdk9 VarHandles

The updateAndGet method is not a part of VarHandles, so is no longer
covered by any existing statement. We will need to somehow do so.

And so, Mike: Some existing code might rely on this, so the best we
could so here is replace elided volatile-write with a fullFence,
which would probably not be detectably faster.


More information about the Concurrency-interest mailing list