[concurrency-interest] Question about reordering and volatile
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.
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."
I'd interpret that to mean that nothing can jump over a volatile access in
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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Concurrency-interest