[concurrency-interest] Racy lazy initialization: blush test

Stanimir Simeonoff stanimir at riflexo.com
Sat Feb 16 07:05:36 EST 2013


There are valid transformations to result into (0,1)/(1, 0)  The 2nd test
obviously should be 1,1 always as x.f is practically ignored for the final
outcome .
Recently there was discussion about that stuff.

Stanimir

On Sat, Feb 16, 2013 at 12:42 PM, 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.)
>
> In that spirit,
>
>           T1        |      T2
>    -----------------+---------------
>    rX1 = x.f        | rX2 = x.f
>    if (rX1 == 0) {  | if (rX2 == 0) {
>        rX1 = 1      |     rX2 = 1
>        x.f = rX1    |     x.f = rX2
>    }                | }
>    r1 = rX1         | r2 = rX2
>
> ...should always yield (r1, r2) = (1, 1).
>
> Thanks,
> Aleksey.
>
> [1]
>
> https://github.com/shipilev/java-concurrency-torture/blob/master/src/main/java/org/openjdk/concurrent/torture/tests/causality/lazyinit/plain/IntLazyTest.java
> [2] http://jeremymanson.blogspot.ru/2008/12/benign-data-races-in-java.html
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20130216/05cfab97/attachment.html>


More information about the Concurrency-interest mailing list