Multithreading 什么';gdb的细节是什么?它有一个线程吗?

Multithreading 什么';gdb的细节是什么?它有一个线程吗?,multithreading,debugging,gdb,pthreads,pthread-join,Multithreading,Debugging,Gdb,Pthreads,Pthread Join,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

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.
gdb,调试代码时它是否持有一个线程

没有

在调用pthread_join()并在主线程中打印“Main exit”之后,始终有一个线程退出。为什么?

glibc发送给GDB的通知告诉它一个线程已经退出,这几乎是一个线程最后做的事情。特别是,该通知是在退出线程通知主线程它已退出之后发送的(即,在退出线程唤醒主线程之后)。因此,在GDB注意到退出线程实际上已经退出之前,主线程醒来并打印
main exit
,一点也不奇怪


我已经运行了很多次,每次“主退出”后只有一个线程

这证明不了什么。如果您运行程序1000000次,可能至少有一次运行GDB会在打印
Main exit
之前注意到线程退出。排序可能取决于您的系统有多少处理器,以及它们有多忙。这里真的没有什么(有趣的)可看的

gdb,调试代码时它是否持有一个线程

没有

在调用pthread_join()并在主线程中打印“Main exit”之后,始终有一个线程退出。为什么?

glibc发送给GDB的通知告诉它一个线程已经退出,这几乎是一个线程最后做的事情。特别是,该通知是在退出线程通知主线程它已退出之后发送的(即,在退出线程唤醒主线程之后)。因此,在GDB注意到退出线程实际上已经退出之前,主线程醒来并打印
main exit
,一点也不奇怪


我已经运行了很多次,每次“主退出”后只有一个线程


这证明不了什么。如果您运行程序1000000次,可能至少有一次运行GDB会在打印
Main exit
之前注意到线程退出。排序可能取决于您的系统有多少处理器,以及它们有多忙。这里真的没有什么(有趣的)可看的

如果从第一个列表中删除GDB消息,则输出几乎相同(仅在分配的地址/ID和
myorder
值的顺序上不同,我认为这是不确定的,因为它可能取决于线程调度)。您如何知道最后一个线程退出在非调试器运行中也没有被阻止,因为您没有关于在这种情况下线程退出何时完成的信息?据你所知,它也可能发生在其他线程上……我已经运行过很多次了,每次“主退出”之后只有一个线程。
Main exit。[线程0xb57d5b70(LWP 9280)已退出]
。如果它是随机的,则应该是两个或三个线程,但不是。如果从第一个列表中删除GDB消息,则输出几乎相同(仅在分配的地址/ID和
myorder
值的顺序上不同,我认为这是不确定的,因为它可能取决于线程调度)。您如何知道最后一个线程退出在非调试器运行中也没有被阻止,因为您没有关于在这种情况下线程退出何时完成的信息?据你所知,它也可能发生在其他线程上……我已经运行过很多次了,每次“主退出”之后只有一个线程。
Main exit。[线程0xb57d5b70(LWP 9280)已退出]
。如果它是随机的,它应该是两个,也许是三个线程,但它不是。