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

Igor Stasenko siguctua at gmail.com
Wed Oct 13 16:22:54 UTC 2010


On 13 October 2010 18:54, Eliot Miranda <eliot.miranda at gmail.com> wrote:
>
> Right.  And because Smalltak can't reify variables and CAS is an operation
> on a variable CAS can't be implemented as a primitive on variables.  There's
> no way to express "pass a variable to a primitive", only "pass an expression
> (which may be the value of a variable)" to a primitive".  One could do it
> with a primitive on an object, e.g. thisContext at: tempIndex compareWith:
> match andSetTo: expr, or anObject instVarAt: varIndex compareWith: match
> andSetTo: expr but that's soooo ugly.  Hence I think it is better done using
> a special assignment operator.

Eliot, if this not a bytecode (which is much more lightweigth to primitive),
then why bother ?

It is trivial to implement a primitive like:

Array>>compareAt: index with: value andStore: anObject
 <primitive: 'primitiveCAS' >
...

so, then you can do:

moo := Array with: 100.

oldValue := moo compareAt: 1 with: 100 andStore: 2.
self assert: oldValue == 100.
self assert: moo first == 2



-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list