gdb的细节是什么,它在调试代码时是否拥有一个线程?
我在主线程中设置了一个退出标志,并且在打印标志之前我已经加入了其他线程。当我在使用参数“-g”编译后使用 gdb 运行调试版本时,它看起来:
[Thread debugging using libthread_db enabled]
Input number of threads:5
Main thread id: 0xb7fda6c0,
[New Thread 0xb7fd9b70 (LWP 9276)]
[New Thread 0xb75d8b70 (LWP 9277)]
[New Thread 0xb6bd7b70 (LWP 9278)]
[New Thread 0xb61d6b70 (LWP 9279)]
[New Thread 0xb57d5b70 (LWP 9280)]
I am thread 0xb6bd7b70, myorder 2, thread_exit.
I am thread 0xb61d6b70, myorder 3, thread_exit.
I am thread 0xb7fd9b70, myorder 0, thread_exit.
I am thread 0xb57d5b70, myorder 4, thread_exit.
I am thread 0xb75d8b70, myorder 1, thread_exit.
[Thread 0xb61d6b70 (LWP 9279) exited]
[Thread 0xb6bd7b70 (LWP 9278) exited]
[Thread 0xb75d8b70 (LWP 9277) exited]
[Thread 0xb7fd9b70 (LWP 9276) exited]
Main: completed join with thread 0xb7fd9b70 having a status of 0
Main: completed join with thread 0xb75d8b70 having a status of 1
Main: completed join with thread 0xb6bd7b70 having a status of 2
Main: completed join with thread 0xb61d6b70 having a status of 3
Main: completed join with thread 0xb57d5b70 having a status of 4
Main: lock will be destroy
Main: 9273, tlist will be free
Main exit.
[Thread 0xb57d5b70 (LWP 9280) exited]
Program exited normally.
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.7.el6.i686 libgcc-4.4.4-13.el6.i686
GDB 提供有关线程“创建”和“退出”的信息。pthread_join()
但是在主线程中调用并打印“Main exit”后总是有一个线程退出。为什么?是 gdb 使用的线程吗?
运行发布版,没什么特别的:
Input number of threads:5
Main thread id: 0xb77176c0,
I am thread 0xb5913b70, myorder 3, thread_exit.
I am thread 0xb4f12b70, myorder 4, thread_exit.
I am thread 0xb6314b70, myorder 2, thread_exit.
I am thread 0xb6d15b70, myorder 1, thread_exit.
I am thread 0xb7716b70, myorder 0, thread_exit.
Main: completed join with thread 0xb7716b70 having a status of 0
Main: completed join with thread 0xb6d15b70 having a status of 1
Main: completed join with thread 0xb6314b70 having a status of 2
Main: completed join with thread 0xb5913b70 having a status of 3
Main: completed join with thread 0xb4f12b70 having a status of 4
Main: lock will be destroy
Main: tdata list will be free
Main exit.