How to assert if a std::mutex is locked?
Strictly speaking, the question was about checking the lockedness of std::mutex directly. However, if encapsulating it in a new class is allowed, it’s very easy to do so: class mutex : public std::mutex { public: #ifndef NDEBUG void lock() { std::mutex::lock(); m_holder = std::this_thread::get_id(); } #endif // #ifndef NDEBUG #ifndef NDEBUG void unlock() { m_holder … Read more