What is the C++ Memory Model, and why is it important for multi-threaded applications?
Last updated
The C++11 memory model is the rules for how threads interact through memory: a happens-before relation for visibility, limits on reordering, and data races as undefined behavior.
It makes concurrent behavior part of the language instead of platform-dependent, so correct threaded code is portable.
You uphold it with
std::mutexorstd::atomic, which create the happens-before edges needed for safe visibility.