[thread] mutex is locked
Dear all, does anybody know if there is a possibility to check if a mutex is locked? There is an 'owns_lock' on the lock type but not on the mutex. The main use case for me is debugging (and documentation) purposes: void MyClass::Process() { boost::unique_lockboost::mutex lck(m_mtx); ProcessImpl(); } void MyClass::ProcessImpl() { _ASSERT(m_mtx.is_locked()); //does not exist :( }
can use this?
bool owns_lock() const;
------------------ Original ------------------
From: "gast128";
maybe you can use the unique_lock's member function bool owns_lock() const; -- View this message in context: http://boost.2283326.n4.nabble.com/thread-mutex-is-locked-tp4664451p4664452.... Sent from the Boost - Users mailing list archive at Nabble.com.
Le 26/06/14 13:46, gast128 a écrit :
Dear all,
does anybody know if there is a possibility to check if a mutex is locked? There is an 'owns_lock' on the lock type but not on the mutex.
The main use case for me is debugging (and documentation) purposes:
void MyClass::Process() { boost::unique_lockboost::mutex lck(m_mtx);
ProcessImpl(); }
void MyClass::ProcessImpl() { _ASSERT(m_mtx.is_locked()); //does not exist :( }
No theres is no such function. I would suggest you to do the following void MyClass::Process() { boost::unique_lockboost::mutex lck(m_mtx); ProcessImpl(lck); } void MyClass::ProcessImpl(boost::unique_lockboost::mutex &lck) { _ASSERT(lck.owns_lock()); // ... } BTW, I use to use this idiom and I use the same function name. Best, Vicente
participants (4)
-
gast128
-
I Do
-
LambdaTea
-
Vicente J. Botet Escriba