Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2006-11-01 16:15:17

On Nov 1, 2006, at 4:06 PM, Roland Schwarz wrote:

> So we would end up with mutex and recursive_mutex, yes?

Instead of a recursive_mutex, how would you feel about a
recursive_mutex *adaptor* (like stack is to containers). Here's a
prototype. Warning, it is not mature:

template <class Mutex>
class recursive_mutex
     Mutex& mut_;
     unsigned count_;
     thread_util::id id_;
     explicit recursive_mutex(Mutex& mut)
         : mut_(mut), count_(0), id_(thread_self::not_any_thread()) {}
     void lock()
         thread_self::id self = thread_self::current();
         if (thread_self::equal(id_, self))
             id_ = self;
             store_release(&count_, 1);

     void unlock()
         if (--count_ == 0)
             id_ = thread_self::not_any_thread();

The basic idea is a mutex *adaptor*. Everything else I have wrong
above is just details. ;-)


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