
Howard Hinnant wrote:
I like the latent_write_lock / upgradeable lock idea proposed by Bruno / Alexander. I have been playing with the following interface:
namespace detail {
template <class RW_Mutex> class read_lock { public: typedef RW_Mutex mutex_type;
explicit read_lock(mutex_type& m, bool lock_it = true); explicit read_lock(upgradable_read_lock<mutex_type>& r); explicit read_lock(write_lock<mutex_type>& w);
~read_lock();
void lock(); bool try_lock(); void unlock(); bool locked() const; operator int bool_type::* () const;
private: read_lock(const read_lock&); read_lock& operator=(const read_lock&); };
[...] Seems very good to me. Also demonstrates a better lock taxonomy (which allows me to include some on-topic content ;-) ): Lock Lock( Mutex&, bool = true ); void lock(); void unlock(); bool locked() const; operator int bool_type::* () const; TryLock: Lock +bool try_lock(); TimedLock: TryLock +bool timed_lock( xtime const & );