Boost logo

Threads-Devel :

From: Frank Mori Hess (fmhess_at_[hidden])
Date: 2007-12-06 17:47:25

On Thursday 06 December 2007 11:14, Anthony Williams wrote:
> That's something worth bearing in mind. There's nothing to stop
> condition::wait being specialized for a lock on a recursive mutex to
> do that.

Is it worth requiring objects modeling the various mutex concepts to
provide some information on the mutex's properties? Like a "static const
bool my_mutex_class::recursive" which is true or false depending on
whether my_mutex_class is a recursive mutex. You could also have similar
static members describing whether the mutex support try locks or timed

Or, the property information could be split out into a separate class, like

template<typename Mutex> class mutex_properties;

sort of like how numeric_limits<> works.

The reason I ask is I'm working on some classes that have a Mutex template
parameter, and it would be useful to be able to query some of the
properties of the mutex. For example, I've got a mutex wrapper class that
automatically checks for cycles in the locking order. But the checking
code varies depending on whether the Mutex parameter is recursive or not
(it should detect an error when trying to recursively lock a non-recursive
mutex, but not when recursively locking a recursive mutex). I'd like to
just have one acyclic_mutex<> wrapper class that works with any kind of
underlying mutex, instead of a acyclic_mutex, try_acyclic_mutex,
recursive_acyclic_mutex, etc.

I suppose I could just implement mutex_properties<> in my library,
providing specializations for all the mutex classes in boost.thread and
for my mutex wrappers. Then I'd put an explicit requirement in my library
that if they want to use some other mutex type as the template parameter,
they also need to implement a mutex_properties<> specialization. A
default mutex_properties<> implementation that corresponds to the minimal
Mutex concept might also be convenient.

Hmm, so I guess my question now is, is it worth providing a
mutex_properties<> class in boost.thread?


Threads-Devel list run by bdawes at, david.abrahams at, gregod at, cpdaniel at, john at