[concurrency-interest] Question about reordering and volatile

Joe Bowbeer joe.bowbeer at gmail.com
Tue Apr 1 18:23:29 EDT 2008


On Tue, Apr 1, 2008 at 2:06 PM, Jeremy Manson wrote:

> "Roach Motel" applies to synchronized blocks -- instructions can move
> into them, but not out.  So, normal accesses can be moved from after a
> monitorexit to before it, and from before a monitorenter to after it.
> That's the roach motel principle.
>
> The same reasoning applies to volatiles under the assumption that a
> volatile write is "the same" as a monitorexit and that a volatile read
> is "the same" as a monitorenter.
>
> So, your answer is that you *can* move normal accesses that occur after
> a volatile write to before it.
>
>
Jeremy,

Is it wrong or misleading for the FAQ to say:

"Under the new memory model, accesses to volatile variables cannot be
reordered with each other or nonvolatile variable accesses."

  http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html#volatile

I'd interpret that to mean that nothing can jump over a volatile access in
either direction...

By the way, the FAQ does later clarify that without a matching read, the
volatile write doesn't happen-before anything, which suggests that unread
volatile writes can be elided.

--Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20080401/7ab63c06/attachment.html 


More information about the Concurrency-interest mailing list