Hi,
Frank Peters wrote:
>
> The specific example I'm thinking of is the one of Figure 6 (p15).
For those of you who don't have the JSR at hand, this is:
Initially, x == y == 0
Thread 1:
r1 = x;
if (r1 == 1)
y = 1;
Thread 2
r2 = y;
if (r2 == 1)
x = 1;
> Specifically, I can't see why it's illegal for me to put, say, the
> thread 2 write (x = 1) in my first round of commits (C1), then put the
> corresponding read (r1 = x) in C2, where it sees 0 and then sees the
> value 1 in E3.
>
> In other words, how do the rules differentiate between the case where
> the conditionals don't exist (and where I presume I would be allowed
> to commit the writes early), and this case, where the conditionals do
> exist.
>
In order to commit writes early, those writes must occur in an execution
whose reads only see writes that happen-before them. In this case, the
only writes that happen-before the reads are the writes of 0 to x and y.
The writes of 1 to x and y will not occur in such an execution, so
they cannot be committed early.
This is a bit of an oversimplification, but it should be enough to
jump-start your intuition. It stems from Rule 4 of the formalism.
> I'm sure it's glaringly obvious, so I hope it's no great trouble for
> someone to enlighten me!
Don't worry - it isn't glaringly obvious! This is fairly confusing
stuff. The last time I gave a talk on this, a very well-known computer
scientist didn't understand this exact example.
Jeremy
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:01:09 EDT