[concurrency-interest] Racy lazy initialization: blush test

Nitsan Wakart nitsanw at yahoo.com
Mon Feb 18 09:32:13 EST 2013

My understanding is that the program is open to SC equivalent interpretation given no hints are given with regards to ordering/concurrency.
Consider the code:
r2 = x.f;
if(x.f == 0){
x.f = 1;
r2 = 1;
Is SC equivalent to the original. The fact that x.f is written to concurrently is not conveyed to the compiler, so as far as it's concerned it's fine. Why would the above interpretation be a good idea I'm not sure, but I think it's allowed.

 From: Aleksey Shipilev <aleksey.shipilev at oracle.com>
To: Dmitry Tsitelov <cit at cit.spb.ru> 
Cc: "Concurrency-interest at cs.oswego.edu" <Concurrency-interest at cs.oswego.edu> 
Sent: Monday, February 18, 2013 10:48 AM
Subject: Re: [concurrency-interest] Racy lazy initialization: blush test
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.


Concurrency-interest mailing list
Concurrency-interest at cs.oswego.edu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20130218/ff56a0f6/attachment.html>

More information about the Concurrency-interest mailing list