In this recipe, we will learn how to deal with objects that are labeled const, but contain std::mutex that must be used to ensure thread synchronization. This recipe is important because it is useful to store std::mutex as a private member of a class, but, as soon as you do this, passing an instance of this object as a constant reference (that is, const &) will result in a compiler error. In this recipe, we will demonstrate why this occurs and how to overcome it.
Understanding what const & mutable mean in the context of multiple threads
Getting ready
Before we begin, please ensure that all of the technical requirements are met, including installing Ubuntu 18.04 or higher and running the following in a terminal window...