[concurrency-interest] question the about the JMM

Larry Riedel larryr at saturn.sdsu.edu
Thu Dec 6 13:24:35 EST 2007


> This isn't just about cache coherence.  It's also about
> compiler optimization.  Consider the following example.
> Initially, p == q, and they are some object with a field x.
> Thread 1:
>     r1 = p.x;
>     r2 = q.x;
>     r3 = p.x;
> Thread 2:
>     q.x = 1;
> 
> This means that r1 and r3 can have the value 0 and r2 can
> have the value 1, even though they are all reading from the
> same memory location.  No sane cache coherence policy would
> allow this when reading from the same variable (although I
> may be misremembering some), but the JMM does.

I do not see that code using any constructs which bring
cache coherence /or/ happens-before into the picture,
unless x is "volatile", in which case I think ending up
with (r2==1) and (r3==0) should not be valid.  What
would be a good example where there is a happens-before
but still r1==r3==0 and r2==1?


Larry



More information about the Concurrency-interest mailing list