From this recipe and the next two, we'll be back in the C++ world. In this recipe, we'll learn about the C++ synchronization building blocks. Specifically, we'll look at using std::lock_guard and std::unique_lock in combination with Resource Acquisition Is Initialization (RAII), an object-oriented programming idiom that makes the code more robust and readable. std::lock_guard and std::unique_lock wrap the C++ concept of mutexes around two classes with the RAII concept. std::lock_guard is the simplest and smallest guard, while std::unique_lock adds some functionality on top of it.
Synchronization building blocks
How to do it...
In this recipe, we'll...