Boost logo

Boost :

From: vicente.botet (vicente.botet_at_[hidden])
Date: 2008-03-17 19:08:44

Hi Klaus,

From: "klaus triendl" <>
To: <boost_at_[hidden]>
Sent: Sunday, March 16, 2008 3:55 PM
Subject: [boost] [thread] Interest in a locking pointer and lockable concept

> Hi,
> is there any interest in something like a locking pointer and a type
> that I call "lockable" that pairs any type with a mutex?
> Inspired by Andrei Alexandrescu's article "volatile - Multithreaded
> Programmer's Best Friend" on ddj I implemented a concept similar to a
> locking pointer called "lock_acquirer" that collects acquisition of a
> mutex and a volatile cast of the locked type. It is even more threadsafe
> to use than a locking pointer.

I'm interested in your implementation, but much more in seen how this
lock_acquirer differs from the locking_ptr and in seen how it can works with
the shared mutex.
Could you be more explicit about how it is more threadsafe?

There are other locking pointer like inspired also by Andrei Alexandrescu's
work that will be interesting as
on_derreference_locking_ptr(on_derreference_lock_acquirer) and

> Additionally I made a class "lockable" that pairs a (volatile) type with
> a mutex type, wrapping both in a distinct type, which has first the
> advantage that the type to protect and the mutex are glued together, and
> second that it encapsulates volatile qualifier correctly.

Related to the lockable class, there is a lot of work on the ACE library
that could inspire you, as lock, adaptive_lock, look_adapter that are the
polymorphic counterpart of mutex.

I'll reserve lockable for the concept Lockable. lockable is not a noum.
Maybe locker. locker<T> will be a model of the Lockable concept.

> Also, the locked type in a lockable can, if wanted, by a restricted
> interface only be accessed by a lock_acquirer thus forcing the
> programmer to a very threadsafe programming style.

Could you show us how?

> I can post my implementation along with a simple example to the boost
> vault.
> Klaus

Please do it if you have not yet done.


Vicente Juan Botet Escriba

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