Boost logo

Boost :

From: vicente.botet (vicente.botet_at_[hidden])
Date: 2008-05-16 16:45:31

Hello boosters ,

While writtig a generic library I have needed some lockable traits
and concepts to be chacked with BCCL.

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 (in quickbook format- sorry I can not attach the html file) as well as the header files (which should with gcc 3.4 on cygwin)

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 defined other classes that could be of general interest.

* A make_lockable class will make Lockable/ShareLocakble/UpgradeLocable the derived
class depending on the Lock parameter. This class could be the base of a monitor class.
It can be used as follows:

class X : public make_lockable<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

There is already something similar in Boost::Interprocess.

* 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, ...>, mpl::and_<is_exclusive_lock<_>,
mpl::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 criteria.

Of course, there is yet a lot of work to do, add lock concepts, lockable and lock concept traits,
document, tests, document, tests ... between others.

As you see there is nothing new, neither complex, only some helper classes making easier the construction of higher abstraction levels, and 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