Suppose we want to write a class type that behaves basically like std::atomic<std::string> would, if it existed. That is, we'd like to make it support atomic, thread-safe loads and stores, so that if two threads are accessing the std::string concurrently, neither one will ever observe it in a "halfway assigned" state, the way we observed a "halfway assigned" int64_t in the code sample in the previous section "The problem with volatile."
The best way to write this class is to use a standard library type called std::mutex. The name "mutex" is so common in technical circles that these days it basically just stands for itself, but originally its name is derived from "mutual exclusion." This is because a mutex acts as a way to ensure that only one thread is allowed into a particular section of...