Glossary · Automation software engineering and architecture
Atomic operation
Also known as: Atomic access
German: Atomare Operation
In software engineering, an atomic operation is an operation that other tasks, threads or interrupts observe as indivisible: it either completes entirely or has not started, with no visible intermediate state. Atomic operations are used to share data safely between concurrent parts of a program.
- Software engineering
In one sentence
An atomic operation executes as one indivisible step, so concurrent tasks or interrupts never see a partial result.
Example
A 64-bit position counter updated by a fast task is read with an atomic access, so a slower task never reads a value with the high and low words from different cycles.
How it applies
- Engineering: On controllers with several tasks or cores, even simple assignments may not be atomic, for example when a variable is wider than the processor's native word or spans several memory locations. Developers need to know which accesses the platform guarantees to be atomic.
- Design: When a data structure is larger than one atomic access, use a Critical section, a lock, or a double-buffer scheme to keep it consistent between tasks.
- Documentation: Programming guidelines and library documentation should state which variables are shared between tasks and how their consistency is ensured. Platform-specific atomicity rules belong in the developer documentation, because they differ between runtimes.
Atomic operation vs. critical section
An atomic operation is indivisible by itself, typically supported by hardware. A Critical section makes a longer sequence of operations behave as if it were indivisible by preventing concurrent access while it runs. Critical sections are more flexible but can block other tasks and cause Deadlock if used carelessly.
Atomicity is not the same as Idempotency, which is about repeating an operation without changing the result.