Re: JavaMemoryModel: correct synchronization

From: Jeremy Manson (jmanson@cs.umd.edu)
Date: Mon Feb 23 2004 - 00:07:50 EST


> Tony,
>
> Tony Hosking wrote:
> > I guess the question is, does the JMM guarantee that T2 sees w == true.
> > Since w is not protected by a monitor is it not reasonable to read w
> > in T2 before T1 releases M?
>
> AFAIK code motion across sync blocks is prohibited. Hence there is no way to
> reorder things such that the read of w can be performed before the write.
> Both the write and read of w could move into the respective sync blocks but
> that doesn't change anything.
>
> Now where it states this in the spec these days I can't say.

We don't make such general statements about code motion because they have
holes in them. So, you can, for example, move code across thread-local
synchronization blocks.

The code motion that is allowed must be inferred from the formal spec.
The spec comes with some appropriate/sample proofs.

Informally, we do give the general rule of thumb that if your accesses are
ordered by synchronization (or volatiles), your code will appear
sequentially consistent (and thus you won't see the effects of
reordering). The public review draft states this on page 13, section 3.4.

                                        Jeremy
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:58 EDT