C++ Memory Model and Data Races
The C++ memory model defines how threads observe reads and writes. A data race on non-atomic memory is undefined behavior; mutexes and atomics create the synchronization needed to safely communicate between threads.
Thread synchronization, visibility, atomics, and undefined behavior from data races.