Boost logo

Boost :

From: Dietmar Kuehl (dietmar_kuehl_at_[hidden])
Date: 2000-08-11 08:24:52

--- jsiek_at_[hidden] wrote:
> I agree. The templated guard class is fine for implementation, but it
> shouldn't be hard coded into the concept requirements, hence the
> nested typedef. One reason for this is that we don't want to add
> lock()/unlock() expressions to the Mutex concept. If those functions
> exist, users will gravitate towards them instead of using the guard.

That is, basically we would define something like this:

  template <typename Mutex>
  struct lock {
    lock(Mutex& m): m_mutex(m) { m_mutex.do_lock(); }
    ~lock() { m_mutex.do_unlock(); }
    // ...
    Mutex& m_mutex;

  struct mutex {
    typedef ::lock<mutex> lock;
    friend class lock;
    // ...
    void do_lock();
    void do_unlock();

This allows the use of a generic "lock" class which does not have to be
reimplemented all the time and at the same time prevents users from
even thinking about using the functions manually. Of course,
applicability of the "lock" class defines a new concept, say
"AutoLockable", basically consisting of the applicability of
and 'do_unlock()' through the class 'lock<Mutex>' (where 'Mutex' is the
class realizing the concept).


Do You Yahoo!?
Kick off your party with Yahoo! Invites.

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