Debugging a deadlock in multithreaded program can be little tricky .
So the rescuer GDB is there for the help.I am just giving here the head start one needs to debug a multithreaded program for deadlocks.
Run your program in GDB, wait until the deadlock happens and then use the following commands.
1.info threads
which will list all of the threads that are running and a little * on the one which is currently running.
Sample output
5 Thread 0x7ffff6be3700 (LWP 20175) 0x00000032cf6de8b3 in select () from /lib64/libc.so.6
3 Thread 0x7ffff75e4700 (LWP 20173) 0x00000032cf6ab15d in nanosleep () from /lib64/libc.so.6
2 Thread 0x7ffff7fe5700 (LWP 20172) 0x00000032cf6cd177 in sched_yield () from /lib64/libc.so.6
* 1 Thread 0x7ffff7fe7720 (LWP 20168) 0x00000032cf6de8b3 in select () from /lib64/libc.so.6
So one can see where all the threads are waiting at this point, so if happens to be a dead lock, threads must be stuck on lock or unlock.
to see whats the thread name and all one can use the following commands.
2. thr 1
which will take us to thread 1 code. You should go to thread which is waiting on some lock or which you think is causing the deadlock.
Sample output
[Switching to thread 1 (Thread 0x7ffff7fe7720 (LWP 20168))]#0 0x00000032cf6de8b3 in select () from /lib64/libc.so.6
3. bt
back trace, tada you should now come to know about ur thread name and all the other details.
Sample output
#0 0x00000032cf6de8b3 in select () from /lib64/libc.so.6
#1 0x000000000040c1fd in blm_rule_recv_worker_start () at some_program.cpp:549
#2 0x0000000000404977 in main (argc=2, argv=0x7fffffffe118) at main_some_prog.cpp:356
Best of luck :D
So the rescuer GDB is there for the help.I am just giving here the head start one needs to debug a multithreaded program for deadlocks.
Run your program in GDB, wait until the deadlock happens and then use the following commands.
1.info threads
which will list all of the threads that are running and a little * on the one which is currently running.
Sample output
5 Thread 0x7ffff6be3700 (LWP 20175) 0x00000032cf6de8b3 in select () from /lib64/libc.so.6
3 Thread 0x7ffff75e4700 (LWP 20173) 0x00000032cf6ab15d in nanosleep () from /lib64/libc.so.6
2 Thread 0x7ffff7fe5700 (LWP 20172) 0x00000032cf6cd177 in sched_yield () from /lib64/libc.so.6
* 1 Thread 0x7ffff7fe7720 (LWP 20168) 0x00000032cf6de8b3 in select () from /lib64/libc.so.6
So one can see where all the threads are waiting at this point, so if happens to be a dead lock, threads must be stuck on lock or unlock.
to see whats the thread name and all one can use the following commands.
2. thr 1
which will take us to thread 1 code. You should go to thread which is waiting on some lock or which you think is causing the deadlock.
Sample output
[Switching to thread 1 (Thread 0x7ffff7fe7720 (LWP 20168))]#0 0x00000032cf6de8b3 in select () from /lib64/libc.so.6
3. bt
back trace, tada you should now come to know about ur thread name and all the other details.
Sample output
#0 0x00000032cf6de8b3 in select () from /lib64/libc.so.6
#1 0x000000000040c1fd in blm_rule_recv_worker_start () at some_program.cpp:549
#2 0x0000000000404977 in main (argc=2, argv=0x7fffffffe118) at main_some_prog.cpp:356
Best of luck :D
Comments
Post a Comment