Doug Lea wrote:
>
> Back to:
>
> int v;
> int getValue() {
> if (v == 0)
> v = computeValue();
> return v;
> }
>
> Is getValue allowed by LC to return zero even in some purely single threaded
> context? The possibility of mirrored memory worlds ...
In LC, if the if block is not going to be executed (the case of v!=0),
and in a single threaded context, both reads have to return the same
value. If v was initialized with zero, then, under LC, getValue would
have to return the result of computeValue(). For programs with no data
races, LC == SC.
w0: int v = something;
r0: if (v==0)
w1: v = computeValue;
r1: return v;
V(r0)={w0}.
if computeValue is called, then V(r1)={w1};
else, V(r1)={w0}.
Adalberto
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:22 EDT