Search⌘ K

The Contract

Understand the fundamentals of the C++ memory model, which defines a critical contract between programmers and the system in multithreading contexts. Discover how this contract shapes program behavior, the challenges of managing data races, and the varying levels of memory consistency in modern C++.

We'll cover the following...

The foundation of multithreading is a well-defined memory model. From the reader’s perspective, it consists of two aspects. On the one hand, there is the enormous complexity of it, which often contradicts our intuition. On the other hand, it helps a lot to get a deeper insight into the multithreading challenges. In the first approach, I want to give you a mental model. That being said, the C++ memory model defines a contract.

The Contract

This contract is between the programmer and the system. The system consists of the compiler that generates machine code and the processor that executes the machine code, and it includes the different caches that store the state of the program. The result is - in the good case - a well-defined executable that ...