[concurrency-interest] Basic thread safetyquestion:final/volatile/synchronized fields

David Holmes dcholmes at optusnet.com.au
Wed Dec 20 18:45:48 EST 2006


> >Passing an object through a thread-safe queue is a common means of
> >safe publication.
> This is where I commonly get confused because of reachability concerns,
> such as your typical parent-child relationships.  If object A is
> effectively immutable I understand it's published safely through a
> thread-safe queue. But what about the references held by A?  If A has a
> reference to B, is B also then considered to be safely published?

Safe-publication is transitive (because happens-before is transitive) as
long as construction happens correctly. Eg:

 construct B
 construct A, storing reference to B
 safely-publish A
 get B

works fine as B was also safely published as the construction of B happend
before the construction of A which happened-before the use of B by virtue of

Of course if you mutate B, or change the B reference in A, after the
publication then that actin must itself be synchronized.

David Holmes

More information about the Concurrency-interest mailing list