Reputation: 471
I have a multithreaded application written in C++. And I'm using mutex for file writes. I have a suspicion that somewhere during the execution of the program, the mutex isn't being released.
So I was wondering if there was a way to check for mutex locks and releases on a file, programmatically or otherwise.
I'm running the code on SuseLinux, btw.
Thanks,
Upvotes: 1
Views: 758
Reputation:
Welcome to the wonderful world of debugging multi-threaded code. There is no magic bullet to solve your problems, but at the very least you should be using RAII idioms to manage your mutex. This means wrapping the mutex in a C++ class that claims the mutex when instances of the class are created and releases it when it (the class instance) is destroyed. You can also profitably log the claim/releases, but be aware that this may introduce timing bugs and artefacts.
Upvotes: 8