>Initially x == y == v == v2 == 0, x and y non-volatile, v and v2 volatile
>Thread 1:
>r1=x
>v=0
>r2=v
>y=1
>Thread 2:
>r3=y
>v2=0
>r4=v2
>x=1
>Then r1==r3==1 becomes possible with the strong and weak interpretations.
How? v=0 has a release fence, and r2=v has an acquire fence, ending up
as a full fence. Same for v2=0; r4=v2;
Certainly you cannot perform r2=v until v=0 has been performed.
>> I also believe volatile variables preventing compile time
>> code motion is
>> a good idea, for the same reason.
>Again, it is a myth that volatile variables prevent compile time code
>motion. They prevent it some of the time but not all of the time. To figure
>out when they do or do not prevent it, we have to reason about the
>happens-before relation.
Hmm, so you say we can re-order the volatiles, if we know they do not
aliase?
v = new Integer(0); // v is volatile Integer
String x = v2; // v2 is volatile String; v and v2 do not alias
// can loading v2 happen prior to storing to v?
>Sarita
Thomas Wang
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:01:00 EDT