Atomics And Concurrency
Jun 16, 2025Atomics And Concurrency. This article explains the importance of memory ordering when writing concurrent programs using atomics. Essentially, data races can occur because compilers and CPUs may reorder instructions. As a result, threads operating on shared data might observe operations in an unintended order.
Some programming languages, such as C++ and Rust, give you finer control over the memory model by exposing detailed options through their atomics APIs. In C++, for example, the memory models include:
- Relaxed: no ordering guarantees
- Sequentially consistent: enforces ordering on paired operations for specific variables
- Release–Acquire: introduces a global ordering barrier
Other languages, like Go, don’t provide this level of control. Instead, Go implements a sequentially consistent memory model under the hood.
Russ Coss does a great job explaining hardware memory models, how different programming languages exposes memory models control and Go’s memory model in the following articles: