An atomic operation is indivisible from the perspective of other threads: they cannot observe it half-complete. It is either done or not done. In C++, atomic types provide atomic operations in most cases. section 5.2 section 5.2
Atomicity matters when threads access shared objects:
- If a load and all modifications to an object are atomic, the load reads the initial value or a value stored by one of those modifications. section 5.2
- Non-atomic operations can expose partially completed changes. Unsynchronized access to non-atomic variables can cause a data race and undefined behavior. section 5.2
- Atomic operations provide low-level synchronization with defined semantics and can support ordering between operations on separate threads. section 1.3.3 section 5.4
Atomicity does not make a multi-part non-atomic operation indivisible: other threads may observe only some constituent atomic operations. Atomic operations are a basis for synchronization, but their memory-ordering details are complex. section 5.2 section 5.0
