[concurrency-interest] a question regarding the double-checke dlocking

Chris Purcell chris.purcell.39 at gmail.com
Sun Jun 18 09:38:37 EDT 2006

> Since , upon monitor release, the cache is flushed to main memory, and since
> the "instance" ref is updated only after the inner monitor is exited and the
> "Something" object created
> inside it, would it ensure a consistent view of the instance pointed-to
> object ?

IIRC, writes can be pulled up before monitor exits. Or, to put it
another way, there's a happens-before between your `new something()`
and the atomic updates ending the synchronized block around it, but no
happen-before between your `new something()` and your `instance =

Also, there's no happens-before between your reading the reference and
your reading the instance it refers to. I'm not sure where Java sits
on the issue of dependencies, but you might luck out there too.

In conclusion, to the best of my recollection, it won't work. Can you
just use the Initialization On Demand idiom, which is known to work?


More information about the Concurrency-interest mailing list