|
Boost : |
From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2008-05-30 06:40:59
"Phil Endecott" <spam_from_boost_dev_at_[hidden]> writes:
> vicente.botet wrote:
>> template <typename Lockable>
>> class shared_lockable_adapter
>> {
>> shared_lockable_adapter(Lockable& mtx): mtx_(mtx) {}
>> ~shared_lockable_adapter() {}
>> void lock_shared() {mtx_.lock();}
>> void unlock_shared() {mtx_.unlock();}
>> bool try_lock_shared() { return mtx_.try_lock();}
>> void lock() {mtx_.lock();}
>> void unlock() {mtx_.unlock();}
>> bool try_lock() { return mtx_.try_lock();}
>> // other functions ....
>> private:
>> Lockable& mtx_;
>> };
>
> So this is a trivial adapter that makes a shared mutex that can't
> actually be shared.
I'm not sure this is such a good idea, as it wouldn't really be
shareable.
> It would also be possible, I think, to make an adapter that actually
> creates a shared mutex from a normal one. I've never had to write a
> read/write mutex but I guess that this is how they are implemented internally.
It's a bit more complicated than that. boost::shared_mutex is
implemented on top of boost::mutex and boost::condition_variable for
pthreads: take a look.
Anthony
-- Anthony Williams | Just Software Solutions Ltd Custom Software Development | http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk