[squeak-dev] Re: [Pharo-project] How about atomic value-swap bytecode?

Igor Stasenko siguctua at gmail.com
Wed Oct 13 20:14:42 UTC 2010


On 13 October 2010 22:58, Igor Stasenko <siguctua at gmail.com> wrote:

>>> moreover, i see no trivial way to implement CAS using atomic swap,
>>> while reverse is trivial.
>>
>> Is it, or does it also rely on uninterruptbility?  Is this right?
>>     v1 :=: v2
>> is equivalent to
>>     [ | scratch |
>>      scratch := v1.
>>      v1 ?= v2 : scratch] whileFalse.
>>      v2 := scratch.
>>
>
> Nope! Not in all cases.
>
For example there may be an algorithms which rely on
that v1 never equal to v2.

> If v1 and v2 having equal significance in algorithm, not just v1,
> then it won't work.
> I mean, if the above will be interrupted after leaving the loop but
> before you assign to v2 (v2 := scratch)
> and your code expects that not only v1 swapped correctly, but v2 as well,
> then you're in trouble.
>
> Swap is symmetric, i.e. v1 :=: v2 should be semantically equal to v2 :=: v1.
> But its not achievable unless its also atomic.
>
> So, i must confess (again), that CAS cannot serve as a complete
> replacement for atomic swap.
>
-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list