[concurrency-interest] RE: Synchronization of data read by multiple threads

Jeremy Manson jmanson at cs.purdue.edu
Sat Oct 29 10:40:31 EDT 2005


Ryan LeCompte wrote:
> Is it possible that the new thread that is running, which it invokes
> isInstantiated() will see the value “false” instead of “true” ? Does
> it have to be declared volatile? Do all variables of the class have
> to be declared “volatile” in order for the newly instantiated thread
> to see their most recently written values? Note that the only time
> the class is used by different threads would be in the main thread
> when it is instantiated (new Test()), and then after that the only
> thread ever reading that particular value would be the newly
> instantiated Thread.
> 

You don't need any additional synchronization in this case.  You can 
conceptualize the call to Thread.start() as being a volatile write, and 
the actual beginning of the thread as a volatile read.  So everything 
that happens before the call to Thread.start() (including object 
initialization) is ordered before and visible to everything that happens 
after the start of the thread.

					Jeremy



More information about the Concurrency-interest mailing list