[concurrency-interest] synchronized constructors
cheremin at gmail.com
Fri Dec 16 05:00:13 EST 2011
> so other threads may observe blank/partial state through `foo` reference. This reordering is
> allowed even if `Foo()` is synchronized.
It's a very good explanation. Only to note -- if constructor is
synchronized, as all other accessors, "partial" state can't be seen.
But, sure, blank state -- can be.
> JMM does guarantee that  cannot be reordered before [B], otherwise
> other threads can observe garbage state. Let's call this the "blank"
> guarantee. It's also a mystery to me why whole-birth guarantee can be
> fundamentally more expensive than blank guarantee.
As far, as I understand, blank guarantee is cheeper since it can be
implemented in batch. AFAIK, it is GC who blanking reclaimed memory,
so it can be done megabytes at once, and publishing reclaimed and
zeroed memory also can be done at one shot. So, the cost is greatly
amortized. But store-store barrier at the end of constructor, which
seems to be required for your whole-birth guarantee can't be
More information about the Concurrency-interest