Boost logo

Boost :

From: Bill Wade (bill.wade_at_[hidden])
Date: 2000-09-08 11:26:13

> From: William Kempf [mailto:sirwillard_at_[hidden]]

> Here's a
> quick "unsafe_lock" template to allow for the functionality being
> requested using nothing but the current boost interface.


For code review let me suggest

1) Consider making locking recursive (change bool m_locked to size_t
2) m_lock might not be properly aligned. Change (these lines aren't

> unsafe_lock(M& mx) : m_mx(mx), m_locked(false) { lock(); }
> new ((void*)m_lock) M::lock(m_mx);
> char m_lock[sizeof(M::lock)];


  unsafe_lock(M& mx): m_mx(mx), m_locked(true), m_lock(mx){}
     new((void*)&m_lock) M::lock(m_mx);
  M::lock m_lock

and change every occurrence of "((M::lock*)m_lock)->" to "m_lock."

Mostly unrelated question:

Have you got a way to atomically convert a non-recursive
MutexTryLock::try_lock into a MutexLock::lock that can be used with a cv?
How do I get non-blocking access to a cv (and its associated mutex)?

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