<div dir="ltr"><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Aug 7, 2014 at 10:00 PM, Ryan Macnak <span dir="ltr">&lt;<a href="mailto:rmacnak@gmail.com" target="_blank">rmacnak@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Aug 7, 2014 at 8:43 PM, Ben Coman <span dir="ltr">&lt;<a href="mailto:btc@openinworld.com" target="_blank">btc@openinworld.com</a>&gt;</span> wrote:<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


I am looking at dealing with multiple in-image threads and am wondering about what operations are atomic.  The current understanding is that...<br>
   (myvar == nil) ifTrue: [ myvar := 1.  myvar2 := #something ]<br>
is atomic, but I see some indication in comments (sorry lost my reference) that...<br>
   myvar ifNil: [ myvar:=1 ]<br>
might not be - but maybe those comments were historical. What is the current status and likely future guarantees for Squeak/Pharo/Cuis/other? </blockquote><div><br></div><div>On Squeak-derived systems the two operations that are not atomic are message sends and backward branches; these are where the VM checks for external events and your process might be preempted by one with a higher priority. </div>
</div></div></div></blockquote><div><br></div><div>That&#39;s very close.  In fact, the two places where the VM tests for events are sends that build a frame and backward branches.  So a send that activates a method that has a primitive that doesn&#39;t fail won&#39;t check for events.  Quick primitives are used to answer inst vars of all objects except contexts, so any inst var fetch of a non-context can be done without a process switch.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>#ifTrue: and #ifNil: are atomic because the bytecode compiler inlines them (#ifTrue: has always been inlined, but I don&#39;t think #ifNil: always was). </div>
</div></div></div></blockquote><div><br></div><div>That&#39;s right.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra">
<div class="gmail_quote"><div>#== is atomic because the VM implements it without a send.</div></div></div></div></blockquote><div> </div><div>And it would still be atomic if sent since it will bind to a non-failing primitive.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> This is all if code runs normally. If run through the debugger you might be interrupted at any operation because the simulation is implemented in terms of Smalltalk code with tons of sends. One should not rely on these implementation details and instead use semaphores or (very rarely) #valueUnpreemptively.</div>
</div></div></div></blockquote><div><br></div><div>It&#39;s very useful for experiments to know what one can get away with.  But the language could add some atomicity operation such as conditional assignment, and that could still be safe if debugged. e.g. (myVar ?== nil := 1) would be a nice syntax, setting myVar to 1 if it is == to nil.  Nice too if this evaluated to a boolean, true if the assignment occurred.</div>
</div><div><br></div>-- <br>best,<div>Eliot</div>
</div></div>