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.