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
std::unique_lock has owns_lock member function (equivalent of is_locked as you say).
std::mutex gmtx;
std::unique_lock glock(gmtx, std::defer_lock);
void alpha(void) {
std::lock_guard g(glock);
beta(void);
// some other work
}
void beta(void) {
assert(glock.owns_lock()); // or just assert(glock);
// some real work
}
EDIT: In this solution, all lock operations should be performed via unique_lock glock not 'raw' mutex gmtx. For example, alpha member function is rewritten with lock_guard (or simply lock_guard).