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

Igor Stasenko siguctua at gmail.com
Wed Oct 13 15:33:50 UTC 2010


On 13 October 2010 18:07, Tom Rushworth <tom_rushworth at mac.com> wrote:
> Hi all,
>
> Take a look through the literature for the "strength" of the various types of atomic operations with respect to doing various synchronization tasks.  CAS is "universal" in the sense that it can simulate all of the others.  (The simulation is wretched, O(N**3), so it isn't practical, but...)
> I doubt that your atomic swap is as strong.

Who said i gonna use it for synchronizations tasks?
We got a plenty of other stuff in smalltalk for synchronization.

>
> Pretty well every current HW architecture actually has the CAS instruction (or some minor variation) implemented as a single instruction, so making it a primitive should be relatively easy. It seems a terrible waste to pick a weak synchronization primitive when a much better one could be had for very little more work.

I feel that you are mixing hardware and language-side atomicity.
I don't care about hardware , i care that at language side i have a
simple atomic operation, which can't be interrupted by scheduler.
Hardware CAS is completely irrelevant to this, since VM can support
atomicity for language side without any specific requirements from the
hardware it runs on.


>
> On 2010-Oct-12, at 12:04, Igor Stasenko wrote:
>
>> CAS? Perhaps. If you wish to add it too, no problem.
>>
>> I want at minimum swap, because with it i can easily implement
>> lock-free waiting:
>>
>> [ | temp |
>>  [ locked ] whileTrue.
>>    temp := true.
>>    locked :=: temp.
>>    temp
>> ] whileTrue.
>
> I think this is simpler (using Eliot's notation):
>
>  [locked ?:= true : false] whileFalse.
>
>   ... locked here ...
>
>   locked := false.
>
> No temp needed, single block. well understood atomic op :).

Yeah? Then try and implement a unconditional atomic swap using CAS.

Again, who said, that i going to use atomic swap for loops like above?
I simply need a guarantee from VM , that swap operation will be
atomic. No less, no more.
Compare-And-Swap and swap is different operations.


> I've used this pattern (expressed in C code) in a very heavily used parallel data processing application, so I can even claim to have tested it extensively :).
>

Yes yes.. But C is not Smalltalk.

>>

-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list