The modification contract
While a program or process is in execution, all the threads in the system should agree on the modification order (for the memory). Every program is executed in an environment, which involves the instruction stream, memory, registers, heap, stack, caches, virtual memory, and so on. This modification order is a contract, between the programmer and system, that is defined by the memory model. The system consists of the compiler (and linker), which morphs the program into executable code, the processor, which executes the instruction set specified in the stream, the cache, and associated states of the program. The contract requires mandating the programmer to obey certain rules, which enables the system to generate a fully optimized program. This set of rules (or heuristics) that a programmer has to conform to while writing code to access memory is achieved with the help of atomic types and atomic operations that were introduced in the standard library.
These operations...