|
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
{
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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk