With GCC 4.8.2 (on Linux/Debian/Sid 64 bits) -or GCC 4.9 when available - in C++11- I have some mutex
std::mutex gmtx;
actually, it is
My solution is simple, use try_lock to test then unlock if needed:
std::mutex mtx; bool is_locked() { if (mtx.try_lock()) { mtx.unlock(); return false; } return true; // locked thus try_lock failed }