You are right that you do not need special instructions for atomic reading of a 32-bit integer, however this means that you will get an โintegerโ value (that is, you will not get part of one record and part of another). You have no guarantee that the value will not change after reading it.
It is at this point that you need to decide whether you need to use some other synchronization method to control access, say, if you use this value to read a member from an array, etc.
In a nutshell, atomicity ensures that the operation is complete and indivisible. Given some operation A containing steps N , if you did this immediately after A , you can be sure that all steps N performed in isolation from parallel operations.
If you had two threads that performed atomic operation A , you are guaranteed to see only the result of complete from one of the two threads. If you want to coordinate threads, you can use atomic operations to create the required synchronization. But atomic operations alone do not provide higher level synchronization. The Interlocked family of methods is available to provide some fundamental atomic operations.
Synchronization is a broader type of concurrency control that is often built around atomic operations. Most processors include memory barriers that allow you to clear all cache lines, and you have a consistent view. Volatile reads are a way to provide consistent access to a specific memory location.
If you are not immediately applicable to your problem, reading ACID information (atomicity, consistency, isolation, and durability) regarding databases can help you in terminology.
user7116 May 26 '11 at 14:01 2011-05-26 14:01
source share