|
Boost : |
From: Mark Rodgers (mark.rodgers_at_[hidden])
Date: 2000-08-10 04:12:29
From: <jsiek_at_[hidden]>
>
> Ok, to help people get a feel for what we want, I've written up a
> strawman concept description for Mutex and ReentrantMutex.
>
> http://www.lsc.nd.edu/~jsiek/Mutex.html
> http://www.lsc.nd.edu/~jsiek/ReentrantMutex.html
Excellent!
Here's my first cut at some of the concepts we might need (with
an Win32 bias I'm afraid).
Lock - Basic wait forever lock
TryLock refines Lock - Allows an immediate return if mutex is locked
TimedLock refines Lock - Allows waiting for a time if unable to lock
mutex before failing
Mutex - Basic non recursive, unnamed, process-local mutex.
RecursiveMutex refines Mutex
NamedMutex refines Mutex - Allows mutex to be "looked up" by
name.
InterprocessMutex refines NamedMutex - Supports inter-process
synchronisation. (I've assumed this is done by name although
Win32 DuplicateHandle could also be used.)
CountedMutex refines Mutex - Allows N simultaneous locks.
Examples in Win32
Critical Section
- Model of RecursiveMutex
- Supports TryLock
Mutex
- Model of RecursiveMutex and optionally InterprocessMutex
- Supports TimedLock
Semaphore
- Model of CountedMutex and optionally InterprocessMutex
- Supports TimedLock
I see a lot of similarities between Mutexes and Containers and
Locks and Iterators, so maybe a Mutex class would have a
single lock type which would be associated with traits that
would in turn give it a category. Then we could dispatch to
different implementations of algorithms based on the lock
category.
So for example we might have
namespace boost {
// tags - just like iterator tags
struct lock_tag {};
struct try_lock_tag : lock_tag {};
struct timed_lock_tag : lock_tag {};
// traits - just like std::iterator_traits
template <typename Lock>
struct lock_traits {
typedef typename Lock::lock_category lock_category;
};
// convenience base class - just like std::iterator
template <typename Category>
struct lock {
typedef Category lock_category;
};
}
class win32_critical_section
(
class lock : public boost::lock<boost::try_lock_tag>
{
...
};
...
};
For this to work, we'd need to define our concepts so that TryLock
did actually refine Lock and provided extended capabilities rather
than different capabilities.
I don't know. Maybe it's just cute and not useful.
Mark
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk