The C++ memory model
This section explains the C++ memory model and how it deals with concurrency. The C++ memory model comes with C++11, and defines the two main features of memory in C++:
- How objects are laid out in memory (that is, structural aspects). This subject won’t be covered in this book, which is about asynchronous programming.
- Memory modification order (that is, concurrency aspects). We will see the different memory modification orders specified in the memory model.
Memory access order
Before we explain the C++ memory model and the different memory orderings it supports, let’s clarify what we mean by memory order. Memory order refers to the order in which memory (that is, the variables in a program) is accessed. Memory access can be either read or write (load and store). But what is the actual order in which the variables of a program are accessed? For the following code, there are three points of view: the written code order, the compiler...