RE: JavaMemoryModel: Race-proof mutable objects and synchronized constructors

From: David Holmes (
Date: Sun Dec 03 2000 - 17:34:33 EST

> Unfortunately, to really make the class race-proof, you need to have
> the constructor be synchronized. Without a synchronized constructor,
> there is nothing that forces the processor that initializes the
> object to send the initializing writes from its cache out to main
> memory.

I had a weird sense of deja-vu when I read this - this is the sort of
discussion we were having a couple of years back and I thought we had
resolved the issues:

- if an object is shared then the shared reference must be set/get using
synchronization, or else accessed via a volatile (or final?) ref in the new

- if the shared object is immutable we can relax the above requirements by
using final fields in the object, and then we don't need to sync (either by
synchronized blocks or volatile) access to the shared reference.

- if an object publishes a reference to 'this' during construction (which
includes inner Runnables) then all bets are off and the code must take
special steps to ensure correctness.

What did I miss??

David Holmes
JavaMemoryModel mailing list -

This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:29 EDT