[concurrency-interest] Can a volatile read be reordered before a lazySet?

Dávid Karnok akarnokd at gmail.com
Tue Dec 23 17:50:09 EST 2014


Hello,

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
ping-pong example:

ping.lazySet(1);
while (pong.get() == 0);

while (ping.get() == 0);
pong.lazySet(1);

i.e., in both threads, the while loops end up before the lazySet and thus
deadlocking.

Best regards,
David Karnok


-- 
Best regards,
David Karnok
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20141223/8dec8826/attachment.html>


More information about the Concurrency-interest mailing list