5 The C++ memory model and operations on atomic types

 

This chapter covers

  • The details of the C++ memory model
  • The atomic types provided by the C++
  • Standard Library
  • The operations that are available on those types
  • How those operations can be used to provide synchronization between threads

One of the most important features of the C++ Standard is something most programmers won’t even notice. It’s not the new syntax features, nor is it the new library facilities, but the new multithreading-aware memory model. Without the memory model to define exactly how the fundamental building blocks work, none of the facilities I’ve covered could be relied on to work. There’s a reason that most programmers won’t notice: if you use mutexes to protect your data and condition variables, futures, latches, or barriers to signal events, the details of why they work aren’t important. It’s only when you start trying to get “close to the machine” that the precise details of the memory model matter.

5.1   Memory model basics

5.1.1   Objects and memory locations

5.1.2   Objects, memory locations, and concurrency

5.1.3   Modification orders

5.2   Atomic operations and types in C++

5.2.1   The standard atomic types

5.2.2   Operations on std::atomic_flag

5.2.3   Operations on std::atomic<bool>

5.2.4   Operations on std::atomic<T*>: pointer arithmetic

5.2.5   Operations on standard atomic integral types

5.2.6   The std::atomic<> primary class template

5.2.7   Free functions for atomic operations

5.3   Synchronizing operations and enforcing ordering

5.3.1   The synchronizes-with relationship

5.3.2   The happens-before relationship

5.3.3   Memory ordering for atomic operations

5.3.4   Release sequences and synchronizes-with

5.3.5   Fences

5.3.6   Ordering non-atomic operations with atomics

5.3.7   Ordering non-atomic operations

5.4   Summary

sitemap