Re: JavaMemoryModel: Code that sleeps and expects to see changes

From: Keith Randall (randall@src.dec.com)
Date: Mon Oct 25 1999 - 18:09:17 EDT


> An example. Initially, a = b = 0:
>
> thread 1 thread 2
> x = a y = b
> synchronized (new Object()) {} synchronized (new Object()) {}
> b = 1 a = 1
>
> Under the old model, it would be impossible for this code to result
> in x = y = 1. But under the new model, since the synchronized blocks
> in the above code are no-ops, it _is legal_ to get a result of x = y
> = 1.

Unless I am misinterpreting things, the result x = y = 1 is illegal in
your new memory model as well. (With or without the synchronized
operation.) One of the two reads x = a or x = b will be the first
instruction to execute, let us assume WLOG that it is x = a. This
instruction will have overwritten_1(a) = {}, previous_1(a) = {w}, and
allWrites(a) = {w}, where w is the write that initialized a. Thus, it
must read 0.

I think the consequence of this example is that it is illegal to
reorder a load after a store. Does anyone know if this is a problem
for current/future architectures? For compilers, this rule makes it
difficult to move stores earlier in the code stream.

By the way, perhaps the example you were thinking of is the following:

initially, a = b = 0.

thread 1 thread 2
  a = 1 b = 1
  synchronized (new Object()) {} synchronized (new Object()) {}
  x = b y = a

Any of the four possible values are allowed for the pair (x,y) with
your new memory model, but the pair (0,0) is not allowed for the old
memory model (but would be allowed by the old model if the
synchronized statements were taken away).

                                       -Keith



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