[concurrency-interest] check that volatile stores are not reordered with volatile loads

Aleksey Shipilev aleksey.shipilev at oracle.com
Wed Dec 3 04:41:26 EST 2014


On 12/02/2014 06:50 PM, Oleksandr Otenko wrote:
> The following proves volatile stores and loads form a total order.
> 
> Thread 1:
> r1=y;
> r2=x;
> 
> Thread 2:
> r3=x;
> r4=y;
> 
> Thread 3: x=1
> Thread 4: y=1
> 
> You shall never observe (r1,r2,r3,r4) = (1,0,1,0)

This is IRIW. A relevant test case:
 http://hg.openjdk.java.net/code-tools/jcstress/file/3b6a31d64cd3/tests-custom/src/main/java/org/openjdk/jcstress/tests/volatiles/VolatileIRIWTest.java

> You can build a similar proof for intra-thread reordering:
> 
> Thread 1:
> y=1;
> r1=x;
> z=1;
> 
> Thread 2:
> r3=z;
> x=1;
> r2=y;
> 
> You shall never observe (r1,r2)=(0,0)

This seems to be a variation of Dekker idiom (if you drop "z"), a
relevant test case:
 http://hg.openjdk.java.net/code-tools/jcstress/file/3b6a31d64cd3/tests-custom/src/main/java/org/openjdk/jcstress/tests/volatiles/DekkerTest.java

> You shall never observe (r1,r3)=(1,1)

True, this is the inverse of Dekker's idiom. jcstress has the
autogenerated test cases for volatile sequential consistency. The
pattern in question is L1_S2_L3__S3_L2_S1__Test.

-Aleksey.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20141203/70a4e0d4/attachment.bin>


More information about the Concurrency-interest mailing list