JavaMemoryModel: New Causality Test

From: Jerry Schwarz (
Date: Tue Feb 10 2004 - 20:23:52 EST

In thinking about "out of thin air" I realized that all the causality tests
are straight line code. What about loops?


Initially: x=0

Thread 1:
while(true) ; // loop
x = 1;

Thread 2:
r = x;

Behavior in question: r=1

Argument for not allowed:
The assignment to x doesn't occur in any execution in program order so r=1
is out of thin air.

Argument for allowed:
In reality the condition in the loop would be some complicated code and the
compiler might not be able to determine whether the loop terminates.
However it still might recognize that x isn't referenced in the loop and
move the assignment to it ahead of the loop.


Personally I think this should be allowed because I think the compiler
optimization is reasonable and forbidding it would probably require
revision of standard optimization technologies. But I don't think it's
allowed by either MP or SC-.

JavaMemoryModel mailing list -

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