[Vm-dev] Cross platform atomicity of #ifNil:

Ryan Macnak rmacnak at gmail.com
Fri Aug 8 05:00:36 UTC 2014


On Thu, Aug 7, 2014 at 8:43 PM, Ben Coman <btc at openinworld.com> wrote:
>
> I am looking at dealing with multiple in-image threads and am wondering
> about what operations are atomic.  The current understanding is that...
>    (myvar == nil) ifTrue: [ myvar := 1.  myvar2 := #something ]
> is atomic, but I see some indication in comments (sorry lost my reference)
> that...
>    myvar ifNil: [ myvar:=1 ]
> might not be - but maybe those comments were historical. What is the
> current status and likely future guarantees for Squeak/Pharo/Cuis/other?


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. #ifTrue: and #ifNil: are atomic because the bytecode compiler
inlines them (#ifTrue: has always been inlined, but I don't think #ifNil:
always was). #== is atomic because the VM implements it without a send.
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20140807/10f767cb/attachment.htm


More information about the Vm-dev mailing list