<div class="gmail_quote">On Mon, Jan 4, 2010 at 6:58 PM, Andrei Alexandrescu <span dir="ltr"><<a href="mailto:andrei@erdani.com">andrei@erdani.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><br>shared int x;<br>...<br>++x;<br><br>The putative user notices that that doesn't work, so she's like, meh, I'll do this then:<br>
<br>int y = x;<br>++y;<br>x = y;<br><br>And the user remains with this impression that the D compiler is a bit dumb. Of course that doesn't avoid the race condition though. If the user would have to call atomicIncrement(x) that would be clearly an improvement, but even this would be an improvement:<br>
<br>int y = sharedRead(x);<br>++y;<br>sharedWrite(y, x);<br><br>When writing such code the user inevitably hits on the documentation for the two intrinsics, which clearly define their guarantees: only the sequence of sharedRead and sharedWrite is preserved. At that point, inspecting the code and understanding how it works is improved.
<div class="im"><br><font color="#888888">...<br></font></div></blockquote>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div class="im"><font color="#888888">Andrei</font> <br></div></blockquote>
<div> </div>
<div>Just to clarify, this is still broken, right? I mean that if two users are calling a method that does this,</div>
<div>the value of x will only get incremented once if their calls to sharedRead/sharedWrite are interleaved?</div>
<div> </div>
<div>Kevin</div>
<div> </div></div>