This lesson briefs the foundation and challenges in the C++ memory model.
The C++ memory model has to deal with the following points:
The foundation of the contract are operations on atomics that have two characteristics: They are by definition atomic or indivisible, and they create synchronization and order constraints on the program execution. These synchronization and order constraints will also hold for operations on non-atomics. On one hand, an operation on an atomic is always atomic; on the other hand, you can tailor the synchronizations and order constraints to your needs.
The more we weaken the memory model, the more we will change our focus towards other things:
To deal with multithreading, we should be an expert. In case we want to deal with atomics (sequential consistency), we should open the door to the next level of expertise. What will happen when we talk about the acquire-release semantic or relaxed semantic? We’ll advance one step higher to (or deeper into) the next expertise level.
Now, we dive deeper into the C++ memory model and start with lock-free programming. On our journey, I will write about atomics and their operations. Once we are done with the basics, the different levels of the memory model will follow. The starting point will be the straightforward sequential consistency, the acquire-release semantic will follow, and the not-so-intuitive relaxed semantic will be the end point of our journey.