|
Boost : |
From: Bronek Kozicki (brok_at_[hidden])
Date: 2004-07-26 08:25:15
Peter Dimov wrote:
> lock lk( m ); // the original examples
>
> with
>
> scoped_lock lock( m );
you still need to select mutex type in lock template class, thus above
would rather look something like:
lock<fast_mutex> lk( m );
or:
scoped_lock<fast_mutex> lock( m );
Assuming that m is actually "fast_mutex". And you need to know its type
whenever you need to lock it or use such lock.
Alternatively, if we have common base class ...
class lock_base {/* .... */};
... typedef ...
typedef const lock_base& lock;
... and number of heloper functions, we could actually write:
lock lk = sole_acquire(m);
or:
lock lk = acquire<scoped_lock>(m);
Please note that no mutex type has been selected (hardcoded) above. The
longer I think about such common base, the more I believe that it should
be just abstract class with very simple interface (virtual destructor;
locked() const; operator safe_bool() const calling locked(); bool
same(const lock_base&) const; operator==(const lock_base&, const
lock_base&) calling same; friend operator!=(const lock_base&, const
lock_base&) calling same;). I will provide some prototype implementation
this week.
B.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk