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

Lawson English lenglish5 at cox.net
Tue Oct 12 21:25:21 UTC 2010


  On 10/12/10 1:51 PM, Andreas Raab wrote:
> On 10/12/2010 6:14 AM, Igor Stasenko wrote:
>> Hello, i just thought, that it would be cool to have a special bytecode,
>> which guarantees atomicity for swapping values between two variables.
>>
>> To swap two values, you usually do:
>>
>> | var1 var2 temp |
>>
>> temp := var1.
>> var1 := var2.
>> var2 := temp.
>>
>> But since its non-atomic, a process can be interrupted and such 
>> operation
>> is not thread-safe.
>
> Actually, this is thread-safe. Process switches happen only on sends 
> and backwards branches.
>
>
So code within blocks methods is thread safe but code that accesses data 
outside of the block/method's scope can't be sure that the external vars 
are consistent?


Lawson







More information about the Squeak-dev mailing list