Assume thread T1 executes the following code:
Foo.x = 1;
Thread t2 = new Thread(task);
Foo.y = 2;
The question is, which writes is t2 guaranteed to see without the
need for any synchronization?
The spec isn't clear on this point, but the only reasonable answer is
that t2 is guaranteed to see both the writes to Foo.x and Foo.y.
Certainly, the revised spec will require that.
I ask because Allen Holub was under the impression that only things
done before the thread creation were guaranteed.
From the JVM point of view, this means that a start() call acts
(roughly) as a memory barrier. Actions before the call to start
cannot be moved to after, and an an SMP, an actual memory barrier
would be required under models such as RMO.
Now, given our recent experience with volatile, I suppose I shouldn't
take anything for granted.
Can we get some feedback from some of the JVM implementors on the
list? Is it clear that this is the only reasonable semantics for
start, and have you implemented the required compiler/memory barriers?
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:26 EDT