Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.
1690 Discussions

For which processors the increment/decrement operations on 32/64 bits integer variables are atomic?

Arethe bellow assumptions correctregarding the increment/decrement operations on Intel processors?
1.Increment/Decrement operations on 32 bits or less integer variableson a single 32 bits processor with no hyper-threading technology are atomic.
2.On a processor with hyper-threading technology or on a multi-processor system, the increment/decrement operations are NOT guaranteed to be executed atomicaly.
How about 64 bits processors?
An official Inteldocument which would describethe atomic operations would be realy wellcomed!

Message Edited by neaflo on 04-06-2005 10:47 PM

0 Kudos
1 Reply
Bellow isthe answer from Intel support team:
The rules for atomic operations may be found in Chapter 7, Locked Atomic Operations, of the IA-32 IntelR Architecture Software Developers Manual, Volume 3: System Programming Guide ( Here, it is guaranteed that simple loads or stores will be automatically atomic as long as the memory location is aligned on the appropriate boundary (16-bit boundary for 16-bit values, 32-bit boundary for 32-bit values, and so forth). In addition, simple loads or stores that are not aligned on the appropriate boundary are still guaranteed to be executed atomically if the 16, 32, or 64-bit values fit completely within a 32-byte cache line. Loads and stores that cross cache lines are not guaranteed to be executed atomically. In these cases, you can use the LOCK prefix to guarantee atomic operation of the simple load or store.
INC and DEC belong to the family of instructions that can read, modify, and write a data value in memory. Thus, their operation is not guarnateed to be atomic unless the LOCK prefix is used for these instructions (when referencing a location in memory). The XCHG instruction automatically causes the LOCK behavior to occur regardless of whether the prefix is used or not.