[concurrency-interest] question the about the JMM

Jeremy Manson jmanson at cs.umd.edu
Thu Dec 6 02:18:24 EST 2007

Larry Riedel wrote:
>> [...] your next paragraph illustrates exactly what's wrong
>> with this mental model, and that is, there is almost
>> always that hidden assumption of sequential consistency.
>> "Before" and "after" simply have no meaning under the JMM
>> except as defined by happens-before.
> I am inclined to expect any intuitive model based on
> the JMM, with a local clock and "happens-before", will
> be homomorphic to a graph for a model based on a global
> clock and local caches (using a typical cache coherence
> protocol), with meaningful and well-defined "before" and
> "after".  But I would rather not try to prove it. (-:


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;

Now, the compiler can remove redundant reads as follows:

Thread 1:
r1 = r3 = p.x;
r2 = q.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.


More information about the Concurrency-interest mailing list