Debugging multi-threaded programs can be really tricky. GDB however, will always do its best to rescue you from whatever horrible bug you’re currently looking at. Today I wanted to show you a really nice command for viewing all the threads in your program.
This particular command isย especially helpful if you ever need to diagnose a deadlock, because it will give you a complete overview of the entire system and allow you to see which locks are currently being requested.
I’m going to use the C++11 threads program from my thread tutorial to illustrate, with one minor modification – I’ve added a sleep command in the thread subroutine. The only reason I’ve done this is because it keeps my threads alive for long enough to show them all to you in the debugger. On a commercial multi-threaded system, your threads will be doing something most of the time, so my sleep command is essentially simulating my threads going off and doing important jobs ๐