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

Ryan LeCompte Ryan.LeCompte at pangonetworks.com
Sun Oct 30 11:49:05 EST 2005

Okay, that sounds fine. However, what about if the main thread (the one that instantiated Test) continues to read values that were set in the constructor? For example, if the main thread does: t.isInstantiated() later on, will it continue to return the value that was set in the constructor when Test was instantiated? Keep in mind that in this particular scenario the values that the main thread will read never change after being initially set in the constructor of Test. There is no need for making the 'instantiated' variable volatile in this case, right? 


-----Original Message-----
From: Jeremy Manson [mailto:jmanson at cs.purdue.edu] 
Sent: Saturday, October 29, 2005 10:41 AM
To: Ryan LeCompte
Cc: concurrency-interest at altair.cs.oswego.edu
Subject: Re: [concurrency-interest] RE: Synchronization of data read by multiple threads

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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20051030/933436a4/attachment.htm

More information about the Concurrency-interest mailing list