[concurrency-interest] Racy lazy initialization: blush test

Dmitry Tsitelov cit at cit.spb.ru
Mon Feb 18 05:39:46 EST 2013


On 16.02.13 14:42 , "Aleksey Shipilev" <aleksey.shipilev at oracle.com> wrote:

>Hi there,
>
>I think it's time to have another argument about racy stuff! :)
>
>I want to assign the grading for some of the new
>java-concurrency-torture tests, and wanted to cross-check the reasoning.
>Given this test [1], what are the plausible outcomes?
>
>In pseudo-code:
>
>   class X {
>       int f;
>   }
>
>   X x = new X();
>
>          T1      |     T2
>   ---------------+---------------
>   if (x.f == 0)  | if (x.f == 0)
>       x.f = 1    |     x.f = 1
>   r1 = x.f       | r2 = x.f
>
>Is there a valid execution which yields (r1, r2) as (1, 0) or (0, 1)?
>(It appears there are valid executions under JMM, mostly because there
>is the data race on x.f; Jeremy had a post [2] about the similar issue
>before, and reaching to the same conclusion.)
>

Could someone point me to a sequentially-consistent execution of this
scenario emitting (1,0)/(0,1) result, please?

>
>[1]
>https://github.com/shipilev/java-concurrency-torture/blob/master/src/main/
>java/org/openjdk/concurrent/torture/tests/causality/lazyinit/plain/IntLazy
>Test.java
>[2] http://jeremymanson.blogspot.ru/2008/12/benign-data-races-in-java.html




More information about the Concurrency-interest mailing list