
Peter Dimov wrote:
class X { private:
mutex mx_;
public:
void lock(); void unlock(); };
Ok, I understand. But how's about the (admittedly strange looking) solution: class X { private: mutex mx_; thread_specifc_ptr<mutex::scoped_lock> lk_; public: void lock() { if (0 == lk_) lk_.reset(new mutex::scoped_lock); lk_->lock(); } void unlock() { lk_->unlock(); } }; Hmm, I am not sure about the implications of thread_specific_ptr being used as a member. Will need to investigate... But in principle it is the same kind of trick I would need to apply if providing lock/unlock on my POD mutex type. I agree however, that a cleaner interface in this respect would be direct access to mutex.lock() mutex.unlock(). Roland