An atomic operation in computer science refers to a set of operations that can be combined so that they appear to the rest of the system to be a single operation.
To the rest of the system, it appears that the set of operations either succeeds or fails all at once. No in-between state is accessible. This is an atomic operation.
Even without the complications of multiple processing units, this can be non-trivial to implement. As long as there is the possibility of a change in the flow of control, without atomicity there is the possibility that the system can enter an invalid state (invalid as defined by the program, a so-called invariant).
This is a trivial example. In a real system, the operations can be more complex and the errors introduced extremely subtle. For example, reading a 64-bit value from memory may actually be implemented as 2 sequential reads of 2 32-bit memory locations. If a process has only read the first 32-bits, and before it reads the second 32-bits the value in memory gets changed, it will have neither the original value nor the new value but a mixed-up garbage value.
Furthermore, the specific order in which the processes run can change the results, making such an error difficult to detect and debug.
Most modern processors have some facility which can be used to implement locking, such as an atomic test-and-set or compare-and-swap operation, or the ability to temporarily turn off interrupts ensuring that the currently running process cannot be suspended.
This article is licensed under the GNU Free Documentation License.
It uses material from the
"Atomic operation".
Home Page • arts • business • computers • games • health • hospitals • home • kids & teens • news • physicians • recreation• reference • regional • science • shopping • society • sports • world