views:

92

answers:

4

What are the possible ways to debug deadlocking threads in a MT program, other than gdb?

A: 

If you're using POSIX, try investigating PTHREAD_MUTEX_ERRORCHECK.

Chris
A: 

I've always invested some time into writing or grafting on a flexible logging facility into projects I've worked on, and it always paid off handsomely in turning difficult bugs into easy ones. At the very least, wrapping locking primitives in functions or methods that log before and after logging, and display the object being locked and the thread that's doing the locking always helped me to zero in on the offending thread in a matter of minutes - assuming that the problem can be reproduced at all, of course.

Loading the program under a debugger is actually a pretty limited method of determining what happened once a process deadlocks, since all it can give you is a snapshot of how badly you messed up, rather than a step by step explanation of how you screwed up, which I find a lot more helpful.

Ori Pessach
+2  A: 

On some platforms deadlock detection tools may help you find already observed and not yet observed deadlocks, as well as other bugs.

On Solaris, try LockLint.
On Linux, try Helgrind or DRD.

Employed Russian
As with all the Valgrind tools, Helgrind can be an amazingly useful tool.
Dan Moulding
A: 

Or get the Intel Thread Checker. Fine work.

xcramps