RE: JavaMemoryModel: Thread starting in constructors

From: David Holmes (dholmes@dltech.com.au)
Date: Mon Mar 11 2002 - 23:51:11 EST


Josh Bloch wrote:
> Clearly I'm being dense here, but why is anything other than (a) legal?
> I always thought that there was implicit synchronization between a thread
> that started a thread and the thread that it started. If anything besides
> (a) is legal, people will be mightily confused.

Well I'm already mightily confused trying to remember all the rules for
this. The problem is not the thread start but that the field assignments
(one or both) might be reordered to occur *after* the thread.start() - so
the new thread would be guaranteed to see only the default initialized
values.

If the field assignments can't be reordered across the thread.start then I
don't remember which rule prevents it. I *think* a sync block would prevent
it so perhaps its the implicit sync block in start() ???

David Holmes

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



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