In this recipe, we will learn how to make thread-safe synchronization wrappers. By default, the C++ standard library is not thread-safe as not all applications will need this functionality. One mechanism to ensure the C++ standard library is thread-safe is to create a thread-safe class, which adds the data structure you wish to use as well as std::mutex to the class as private members, and then reimplements the data structure's functions to first acquire std::mutex and then forward the function call to the data structure. The problem with this approach is there is a lot of extra code that is added to your program if the data structure is a global resource, making the resulting code hard to read and maintain.
This recipe is important because it will demonstrate how to address these issues in your code by making thread-safe...