On 14 November 2013 10:15, Stephan Eggermont <step...@stack.nl> wrote:
> Reading this code, made me wonder what operations are actually atomic. > Anyone having a good explanation? > > Stephan > > AtomicQueueItem>makeCircular > "Make a receiver circular, i.e. point to itself, > answer the old value of next variable. > Note, this operation should be atomic" > > | temp | > > " atomic swap here" > temp := next. > next := self. > > ^ temp > > imagine that i rewrite it with following: temp := self. temp <=> next. ^ temp here the <=> is a special 'atomic swap' operation which atomically swaps values of two variables. The best way to do that is to introduce a special bytecode in VM, which either swaps values of two temps or swaps values of temp and instance variable. If we could have such bytecode, then we would have a strong guarantee from VM about atomicity of certain operations, but since we don't have it yet, right now it is just (ab)uses the intrinsic behavior of VM, knowing that it never interrupts between two simple assignments. -- Best regards, Igor Stasenko.