JavaMemoryModel: Dropping coherence is more complicated than we thought

From: Doug Lea (
Date: Sun Nov 07 1999 - 19:54:16 EST

> Now we could fix it by writing it as:
> int v;
> int getValue() {
> int tmp = v;
> if (tmp != 0)
> tmp = v = computeValue();
> return tmp;
> }
> But that coding style is ugly, and it would be nice if we weren't force to
> write code that way. Secondly, it would normally be a legal (although
> dubious) compiler transformation to use forward substitution to transform
> the second version of getValue into the first. Now, that becomes illegal.

I think it is illegal already. The value of an assignment statement is
the value of its right hand side, which need not be the value of a
variable accessible across multiple threads that has at some point
been written the value of the rhs. Which means that it is already
illegal to set tmp (or the equivalent in a return statement) by
reading v.

JavaMemoryModel mailing list -

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