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

Stefan Marr squeak at stefan-marr.de
Tue Oct 12 21:21:40 UTC 2010


On 12 Oct 2010, at 22:51, 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.
Please, do not rely on such implementation details, and please do not advocate them.
You will never know where your code is running on tomorrow...

http://permalink.gmane.org/gmane.comp.lang.smalltalk.squeak.general/152184

Best regards
Stefan


-- 
Stefan Marr
Software Languages Lab
Vrije Universiteit Brussel
Pleinlaan 2 / B-1050 Brussels / Belgium
http://soft.vub.ac.be/~smarr
Phone: +32 2 629 2974
Fax:   +32 2 629 3525




More information about the Squeak-dev mailing list