Memory model

define how threads interact with shared memory: when multiple threads may access same memory location and when writes become visible to other threads

Concepts

Rules

Atomic ops

An atomic operation is an operation that is guaranteed to execute as a single transaction. Other threads see the state of the system either before or after the operation, but not any intermediate state.

At low level, atomic operations are special hardware instructions.

std::atomic

#include <atomic>

std::atomic<int> x(0);
++x; // now ++x is atomic

eligible types