Before a thread locks a mutex, I want to check whether it has already got a lock on that mutex so I can’t do this:
Acquire mutex
Acquire mutex
// do something here
Release mutex
// still has mutex lock at this point!!
I know I could just use a bool here, but wanted to know if something already exists.
Thanks.
If you’re using a specific platform (Win32?) mutex implementation – then you should consult that platform’s documentation.
If you’re using C++11 standard mutex – std::mutex, switch to std::recursive_mutex instead. Note that you’ll need to call unlock() for each call to lock().