Boost logo

Boost :

From: Roland Schwarz (roland.schwarz_at_[hidden])
Date: 2006-11-01 16:39:15

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

     mutex mx_;
     thread_specifc_ptr<mutex::scoped_lock> lk_;
     void lock()
         if (0 == lk_) lk_.reset(new mutex::scoped_lock);

     void 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().


Boost list run by bdawes at, gregod at, cpdaniel at, john at