[concurrency-interest] concurrency puzzle

Jeremy Manson jmanson at cs.umd.edu
Mon Sep 11 03:12:47 EDT 2006

This is off list, as it is probably a little more obscure than most 
people will want to tackle.

David Holmes wrote:

> Wow! That is a very subtle distinction. I'm not sure there are any practical
> consequences arising from it but I find it disconcerting to have this
> difference.

I think it is the least disconcerting of the possible alternatives:

If we picked the semantics of the variable initializer, and gave it to 
the default write, then the default write wouldn't be guaranteed to be 
seen by every thread that reads a reference to that object via a data 
race.  You can't see a garbage value, so what value do you see?

If we picked the semantics of the default write, and gave it to the 
variable initializer, then writes made in constructors would have to 
propagate to every thread that sees a reference to the object.  This 
would have a pretty big performance impact.

If we picked the semantics of the default write, and gave it to only the 
variable initializers that write out default values, then you have far 
worse problems, because you are
	a) creating yet another obscure corner case for Java;
	b) in practice, relying on the compiler or virtual machine to detect 
and remove writes of the default value in a variable initializer, so 
that other threads don't see them out of order.  Not only is this not 
always possible, but it is bad for the spec to require certain 
optimizations to occur; and
	c) (and possibly worst of all) changing the memory semantics based on 
which value is written out to a field.

These are all straw men, but I can't really think of a better "fifth 
way" to do this.


More information about the Concurrency-interest mailing list