[concurrency-interest] Can a volatile read be reordered before a lazySet?
akarnokd at gmail.com
Tue Dec 23 17:50:09 EST 2014
Given two atomic values held by an AtomicLong and an AtomicReference, is it
possible the following two lines may be reordered?
theLong.lazySet(theLong.get() + 1);
Object o = theRef.get();
On X86, the memory model states that reads may be reordered with older
writes to different locations, so the algorithm fragment above might be
broken. For context, this code is part of a single-producer structure wich
protects the use of theRef value with an ingress/egress counter pair.
I wonder if the same reordering might happen in a classical atomic
while (pong.get() == 0);
while (ping.get() == 0);
i.e., in both threads, the while loops end up before the lazySet and thus
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Concurrency-interest