[concurrency-interest] Racy lazy initialization: blush test

Boehm, Hans hans.boehm at hp.com
Mon Feb 18 12:32:35 EST 2013

I think some things got confused here, including the rules for different languages.

The basic rules are:

In basically all modern languages: IF THERE ARE NO DATA RACES and no uses of atomics/volatiles, you get sequential consistency.

In Java, C, C++: If there are no data races, and accesses to atomics/volatiles don't say otherwise, you still get sequential consistency.  (This doesn't hold in C# or OpenMP, for example.)

In the presence of data races, these languages instead provide really weak or no guarantees.  The examples under discussion here have data races, so none of this applies.


From: concurrency-interest-bounces at cs.oswego.edu [mailto:concurrency-interest-bounces at cs.oswego.edu] On Behalf Of Nitsan Wakart
Sent: Monday, February 18, 2013 6:32 AM
To: Aleksey Shipilev; Dmitry Tsitelov
Cc: Concurrency-interest at cs.oswego.edu
Subject: Re: [concurrency-interest] Racy lazy initialization: blush test

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<mailto:aleksey.shipilev at oracle.com>>
To: Dmitry Tsitelov <cit at cit.spb.ru<mailto:cit at cit.spb.ru>>
Cc: "Concurrency-interest at cs.oswego.edu<mailto:Concurrency-interest at cs.oswego.edu>" <Concurrency-interest at cs.oswego.edu<mailto: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<mailto:Concurrency-interest at cs.oswego.edu>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20130218/9f473de5/attachment.html>

More information about the Concurrency-interest mailing list