Re: JavaMemoryModel: Re: JMM problems with latch or copy-on-write?

From: Jeremy Manson (
Date: Fri Mar 30 2001 - 17:59:32 EST

> >>
> >> thread 1: initialized = true
> >> thread 1: synchronized(obj) { }
> >> thread 2: synchronized(obj) { }
> >> thread 2: assert(initialized == true)
> >
> > Eep! That won't work, because in our model (again, can't speak for CRF),
> > useless synchronization can be optimized away. Plus, oh, your next point.
> It's unclear what "useless" means in your paper. The semantics paper I
> found online says that a synchronized(obj) could be eliminated if only one
> thread was locking on the object. This isn't the case in the example above.

You are quite right. My brain was disabled, a condition I can only
ascribe to having to run up to New York and not reading my own email
or yours carefully enough. I apologize.

In our model, thread-local lock regions can be eliminated, which is what I
was thinking of. However, there is still the point that you made, which
is that the first line of thread 1 can be reordered to earlier in
the program (before the initialization) and then execute. If thread 2 is
switched to after that, the second thread may not see any of the
initialization (which has not been performed yet), and yet hink
synchronized was true. Unless you are clever and use volatiles and finals
correctly, this is a good idiom to avoid.

JavaMemoryModel mailing list -

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