<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.apple-tab-span
        {mso-style-name:apple-tab-span;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">I think some things got confused here, including the rules for different languages.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">The basic rules are:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">In basically all modern languages: IF THERE ARE NO DATA RACES and no uses of atomics/volatiles, you get sequential consistency.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">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.)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">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.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Hans<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> concurrency-interest-bounces@cs.oswego.edu [mailto:concurrency-interest-bounces@cs.oswego.edu]
<b>On Behalf Of </b>Nitsan Wakart<br>
<b>Sent:</b> Monday, February 18, 2013 6:32 AM<br>
<b>To:</b> Aleksey Shipilev; Dmitry Tsitelov<br>
<b>Cc:</b> Concurrency-interest@cs.oswego.edu<br>
<b>Subject:</b> Re: [concurrency-interest] Racy lazy initialization: blush test<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black">My understanding is that the program is open to SC equivalent interpretation given no hints are given with regards to ordering/concurrency.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black">Consider the code:<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black">r2 = x.f;<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black">if(x.f == 0){<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span class="apple-tab-span"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black">         
</span></span><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black">x.f = 1;<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span class="apple-tab-span"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black">         
</span></span><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black">r2 = 1;<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black">}<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black">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.<o:p></o:p></span></p>
</div>
<div>
<div>
<div>
<div class="MsoNormal" align="center" style="text-align:center;background:white">
<span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black">
<hr size="1" width="100%" align="center">
</span></div>
<p class="MsoNormal" style="background:white"><b><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black">From:</span></b><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black"> Aleksey Shipilev <<a href="mailto:aleksey.shipilev@oracle.com">aleksey.shipilev@oracle.com</a>><br>
<b>To:</b> Dmitry Tsitelov <<a href="mailto:cit@cit.spb.ru">cit@cit.spb.ru</a>> <br>
<b>Cc:</b> "<a href="mailto:Concurrency-interest@cs.oswego.edu">Concurrency-interest@cs.oswego.edu</a>" <<a href="mailto:Concurrency-interest@cs.oswego.edu">Concurrency-interest@cs.oswego.edu</a>>
<br>
<b>Sent:</b> Monday, February 18, 2013 10:48 AM<br>
<b>Subject:</b> Re: [concurrency-interest] Racy lazy initialization: blush test</span><span style="color:black"><o:p></o:p></span></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt;background:white"><span style="color:black"><br>
On 02/18/2013 02:39 PM, Dmitry Tsitelov wrote:<br>
>>  class X {<br>
>>      int f;<br>
>>  }<br>
>><br>
>>  X x = new X();<br>
>><br>
>>          T1      |    T2<br>
>>  ---------------+---------------<br>
>>  if (x.f == 0)  | if (x.f == 0)<br>
>>      x.f = 1    |    x.f = 1<br>
>>  r1 = x.f      | r2 = x.f<br>
>><br>
>> Is there a valid execution which yields (r1, r2) as (1, 0) or (0, 1)?<br>
>> (It appears there are valid executions under JMM, mostly because there<br>
>> is the data race on x.f; Jeremy had a post [2] about the similar issue<br>
>> before, and reaching to the same conclusion.)<br>
>><br>
> <br>
> Could someone point me to a sequentially-consistent execution of this<br>
> scenario emitting (1,0)/(0,1) result, please?<br>
<br>
I'm afraid there are no SC executions that yield this result. We have<br>
the data race on x.f, DRF guarantee is out of the window, it's useless<br>
to seek SC execution to justify this behavior.<br>
<br>
-Aleksey.<br>
<br>
_______________________________________________<br>
Concurrency-interest mailing list<br>
<a href="mailto:Concurrency-interest@cs.oswego.edu">Concurrency-interest@cs.oswego.edu</a><br>
<a href="http://cs.oswego.edu/mailman/listinfo/concurrency-interest">http://cs.oswego.edu/mailman/listinfo/concurrency-interest</a><br>
<br>
<o:p></o:p></span></p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>