[concurrency-interest] when is safe publication safe?

Jochen Theodorou blackdrag at gmx.org
Fri Apr 23 08:36:11 EDT 2010

hi all,

assuming I have Thread t1, that creates an object x and assigns it for 
example to a field and Thread t2 is reading that field. Am I now right 
in assuming that unless I have memory barriers in t1 and t2 I have no 
way to ensure that t2 will see a fully initialized object (x represents 
a mutable)? Am I right that for example AtomicReference#lazySet will not 
help me here? I am aware that this question goes in the direction of 
double checked locking (only no instantaneous visibility and no 
singleton), that is why I assume that it cannot be guaranteed. 
Especially since there will be no "happens-before" relation in t2.

Assuming that I am right I have further questions... For example why was 
it decided that an object can be seen uninitialized by another thread? I 
mean, sure I am aware of reordering of instructions, but does it give 
really that much to make an object visible to another thread without 
having it initialized?

And finally I did read here about Fences. Would they help making my safe 
publication possible?

bye blackdrag

Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)

More information about the Concurrency-interest mailing list