is +=1 thread safe

Bjoern Schliessmann usenet-mail-0306.20.chr0n0ss at spamgourmet.com
Sun May 4 06:17:24 EDT 2008


Gary Herron wrote:

> No NO NO!   The only way to increment a variable in memory is
> through a three step process:
> 
>   Load a register from a memory location
>   Increment the register
>   Store the value back into memory.

I suggest you read "Intel 64 and IA-32 Architectures Software
Developer's Manual" (2A, Instruction Set Reference A-M). INC and
DEC can have register *or* memory location as operand, and can be
executed atomically even in multiprocessor environments (LOCK
prefix).
 
> Ages ago, there were architectures that would do an increment on a
> memory location in an atomic way, but with the current (RISC)
> architectures these are three separate operations.

That may be true for RISC architectures. Unfortunately, all 8086
based CPUs are CISC.

Regards,


Björn

-- 
BOFH excuse #277:

Your Flux Capacitor has gone bad.




More information about the Python-list mailing list