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

Vitaly Davidovich vitalyd at gmail.com
Wed Dec 31 10:18:02 EST 2014

Write buffers don't *need* to be drained, they drain automatically anyway.
At least that's the case for intel.  So the issue here is more like what
Gil said - compiler can reorder the code causing a deadlock.

Sent from my phone
On Dec 31, 2014 9:45 AM, "Oleksandr Otenko" <oleksandr.otenko at oracle.com>

>  Not sure why you say (3). Since lazySet is not part of JMM, I am only
> assuming it is pretty much like an ordered store on x86.
> In the presence of write buffers the loop may spin indefinitely, yet the
> lazy-stored write won't become visible to the pong thread - there'd be
> nothing to cause the buffers of the ping thread to flush. So ping
> effectively will appear to perform all the loads of the indefinite loop
> ahead of the store.
> In reality the only event that would cause the write buffers to flush, is
> the thread preemption.
> Alex
> On 31/12/2014 07:20, Nitsan Wakart wrote:
> Re-read the Shipilev "JMM Pragmatics" reference again last night, and
> discussed with Gil. I think that cup of coffee was nowhere near enough :-).
> In particular:
>  "If IUC this means stores and volatile loads are conservatively not
> reordered" is FALSE because the premise "IUC" is false. I did not
> understand correctly which leads me to amend my comment:
> 1. There's technically nothing to stop reordering between the store and
> load.
>  >  theLong.lazySet(1L);
> >  Object o = theRef.get();
>  2. There's technically nothing to stop reordering between the store and
> load.
> >  long l = theLong.get() + 1; // LOADLOAD
> >  theLong.lazySet(l); //STORESTORE
> >  Object o = theRef.get(); // LOADLOAD
>  3. I still think the while loop presents a different case to normal
> flow. So for now I still hold that the lazySet cannot be moved after the
> while loop.
>  My sincere apologies for the confusion.
> Happy holidays to all.
> _______________________________________________
> Concurrency-interest mailing listConcurrency-interest at cs.oswego.eduhttp://cs.oswego.edu/mailman/listinfo/concurrency-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20141231/aea27b5b/attachment.html>

More information about the Concurrency-interest mailing list