[concurrency-interest] Racy lazy initialization: blush test

Timothy Chen tnachen at gmail.com
Mon Feb 18 16:39:32 EST 2013


Just curious, you said C# doesn't give you sequential consistency in no
data races and no atomics/volatiles usage, then what does C# do?

Is the behavior documented somewhere?

Thanks,

Tim



On Mon, Feb 18, 2013 at 11:59 AM, Boehm, Hans <hans.boehm at hp.com> wrote:

>  On rereading, I think I misunderstood the context here. When Nitsan said
> “SC equivalent”, I think he meant “sequentially equivalent”, in which case
> I now understand the original posting.  Sorry about that.****
>
> ** **
>
> I agree that this is a valid transformation.****
>
> ** **
>
> Hans****
>
> ** **
>
> *From:* concurrency-interest-bounces at cs.oswego.edu [mailto:
> concurrency-interest-bounces at cs.oswego.edu] *On Behalf Of *Boehm, Hans
> *Sent:* Monday, February 18, 2013 9:33 AM
> *To:* Nitsan Wakart; Aleksey Shipilev; Dmitry Tsitelov
> *Cc:* Concurrency-interest at cs.oswego.edu
> *Subject:* Re: [concurrency-interest] Racy lazy initialization: blush test
> ****
>
> ** **
>
> 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.****
>
> ** **
>
> Hans****
>
> ** **
>
> *From:* concurrency-interest-bounces at cs.oswego.edu [
> mailto:concurrency-interest-bounces at cs.oswego.edu<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>
> *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.
>
> -Aleksey.
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest****
>
> _______________________________________________
> 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/20130218/87966817/attachment.html>


More information about the Concurrency-interest mailing list