Boost logo

Boost :

From: vicente.botet (vicente.botet_at_[hidden])
Date: 2008-05-10 12:59:36

Hello boosters ,

While writtig a synchronization library I have needed some lockable traits
and concepts.

If you think that these classes are of general use it will be a pleasure for
me, if Anthony accepts, to included them on the Boost.Thread library.
Otherwise I will left them in my sync library. For the moment all is defined
in a sync (as synchronization) namespace and directory but this is without

Attached a short introduction as well as the header files.

Of course all this is subject to discusion, naming and file structure
changes, ...

For each one of the mutex in the thread library, we need to
* make the mutex inherit from the helper lock_traits_base or
* have nested typedefs or
* specialize each one of the traits templates

As an external library I have do this in a non-intrusive way as for example:

struct timed_interface_tag<boost::mutex> {
    typedef hasnt_timed_interface_tag type;
struct reentrancy_tag<boost::mutex> {
    typedef non_recursive_tag type;
struct category_tag<boost::mutex> {
    typedef exclusive_lock_tag type;
struct scope_tag<boost::mutex> {
    typedef multi_threaded_tag type;

But if included in the Thread library it will be better to use one of the
intrusive methods.

I have also other classes that could be of general interest.

* A make_..._lockable set of mixin class will make lockable the derived
It can be used as follows:

class X : public make_exclusive_lockable<X, boost::mutex> {


X x;

unique_lock<X> lock(x);

* a ..._synchronization_family set of classes that can be used as follows:

template <class SyncFamily> message_queue;

typedef message_queue<thread_synchonization_family> my_mt_message_queue;
typedef message_queue<null_synchonization_family> my_st_message_queue;

The null_synchonization_family needs a null_mutex and a null_condition

* To finish, I'm working on a filter_matching_lockables meta-function which
take as parameter a vector of lockables types and will filter the lockables
types not satisfying a list of traits. The use shoul be somthing like

typedef filter_matching_lockables<vector<boost::mutex,
boost::recursive_mutex, ...>, and_<is_exclusive_lock<_>,
not_<is_recursive_lock<_> > >::type candidates.

and a find_best_lock which choose between the lockables given as parameter
the best one following a given criterium.

Of course, there is yet a lot of work to complete, add lock concepts,
document, tests, document, tests ... between others, that I will be please
to do even if included in the Thread library.

As you see there is nothing new, neither complex, only some helper classes
that currently are missing in boost.

Have a good code reading and please let me know what do you think.
Vicente Juan Botet Escriba

Boost list run by bdawes at, gregod at, cpdaniel at, john at