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

David Holmes dholmes at dltech.com.au
Sun Oct 30 18:28:28 EST 2005


> 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?

No. If the thread doing the construction publishes the reference to the
newly constructed object in an unsafe manner (ie without synchronization)
then other threads accessing the object need not see the constructed state
of its fields (unless they are final or volatile).

David Holmes

More information about the Concurrency-interest mailing list