Atomic operations take an optional memory order that says what other memory the operation makes visible. The default and strongest is std::memory_order_seq_cst: all threads agree on one order of all such operations. Weaker orders cost less on some processors, and lock-free queues use them:
memory_order_relaxed: the operation is atomic, and nothing more. Right for counters nobody synchronizes on.
- release and acquire work in pairs. A
store(v, memory_order_release) publishes every write the thread made before it; a load(memory_order_acquire) that reads that value sees all of those writes. This is how one thread hands data to another: write the data, then release-store a flag or an index.
- Without the pair, a reader can see the flag set and still read old data.
The exercises ask you to predict which results a program can produce under each order, the way interviews and code reviews do, and then to choose orders for real uses. The next unit, Running threads, runs code like this on threads in a simulator; it runs every atomic in order, so these lessons remain the place to reason about weaker orders.
Release publishes the slot; acquire on the same variable makes it visible.