boost::shared_ptr boost::mutex and copy constructor
问题 I need to protect the access to a data structure in my class. As I can't have mutex (because I can't copy it) I am considering to have shared_ptr and keep the mutex there. Here is a sample code of my idea: class Sample { typedef boost::lock_guard<boost::mutex> AcquireLock; boost::shared_ptr<boost::mutex> mutt; public: Sample() : mutt(new boost::mutex) {} void Method() { AcquireLock lock(*mutt); //do some work here } }; I've got the following questions: Is it a bad practice to use the mutex