Atomic operation

from Wikipedia, the free encyclopedia

In computer science , an atomic operation (from the Greek άτομο átomo , 'indivisible') describes a group of individual operations that can be viewed as a logical unit and only run successfully or fail as a whole.

The individual operations can in turn consist of smaller atomic operations, if they fail, the higher-ranking operation is to be regarded as having failed in its entirety. The aim is to make it easier to keep track of the many possible incorrect intermediate states at every level and to be able to reset the operation to what you consider to be a consistent state in the event of a failure .

The term is mainly used in database theory and on certain CPU commands .

Atomic CPU-level operations

Atomic operations are primarily to implement locking mechanisms ( locking ) used in the synchronization of data and processes (see process synchronization are used). Another variant is the non-blocking synchronization of data structures, whereby objects are only modified by atomic operations and the explicit locking of the objects is thereby superfluous.

Typical CPU instructions for implementing atomic operations on current processors are e.g. B. Compare-and-swap or load-link / store-conditional command pairs on RISC architectures.

Atomic database operations

A series of changes to a database can be combined into one transaction , which is either successful as a whole ( commit ) or can be undone by a rollback . Other properties of transactions that are desirable in addition to atomicity are mostly summarized under the acronym ACID .

Atomic operations in programming languages

Some programming languages ​​include concepts to support atomic operations. For example, in Java there is the package java.util.concurrent.atomicwith classes that support atomic comparison or exchange. In Go , too, there is native support in the sync/atomicpackage.