I’d like to add some debugging code to an abstraction of pthread_cond_wait in my code to check that the calling code really holds the mutex, as it should. This is to check correctness of the rest of the callers.
Is there a way to check if the mutex is locked, or enable a debug mode in the pthreads implementation (on Linux) to tell me if it’s not?
If you create the mutex as an error-checking mutex, using:
…then
pthread_cond_wait()will returnEPERMif the mutex is not locked by the calling thread.(of course you would add error-checking to that mutex initialisation code).
I think error-checking mutexes are exactly the kind of “debugging mode” that you’re looking for.