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

From: Bill Pugh (pugh@cs.umd.edu)
Date: Mon Oct 25 1999 - 13:24:03 EDT


>Note that the synch is needed to do the wait, in:
>
> > if (millisecs != 0) {
> > Object s = new Object();
> > synchronized(s) { s.wait(millisecs); }
> > }

Yes, I understand the reasoning for the sync.

>
>But I don't understand the sense in which you mean that it was a
>global barrier under old model. If thread A sleeps, and then looks at
>a field that was modified by thread B, but thread B has not released a
>lock, then thread A may still be seeing old value.

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.

        Bill

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



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