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

Larry Riedel larryr at saturn.sdsu.edu
Sat Oct 29 13:00:23 EDT 2005

> Class Test implements Runnable {
>    Private boolean instantiated = false;
>    Public Test() { Instantiated = true; }
>    private boolean isInstantiated() { Return instantiated; }
>    Public void run() { 
>          If (isInstantiated()) 
>             // do something 
> And then somewhere in the main thread we do the following:
> Test t = new Test();
> Thread th = new Thread(t);
> t.start();

I would like to think there will only ever be one thread
aware of the existence of an object before it has
been completely constructed (assuming, of course, the
constructor does not give away references to itself),
and consequently no other thread will see any state the
object was in before its construction was complete.  In
other words all these things about "happens before" only
apply to changes which take place after another thread
has been given a reference to the object, and that can
only happen after its construction is complete.

But is this correct?


More information about the Concurrency-interest mailing list