[concurrency-interest] Racy lazy initialization: blush test

Aleksey Shipilev aleksey.shipilev at oracle.com
Mon Feb 18 05:48:06 EST 2013


On 02/18/2013 02:39 PM, Dmitry Tsitelov wrote:
>>   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?

I'm afraid there are no SC executions that yield this result. We have
the data race on x.f, DRF guarantee is out of the window, it's useless
to seek SC execution to justify this behavior.

-Aleksey.



More information about the Concurrency-interest mailing list