子进程在父进入加入之前到达退出时如何在父线程中收集子线程状态?

时间:2016-12-05 10:13:57

标签: linux multithreading pthreads

在我的场景中,主线程正在使用pthread_create()创建3个子线程。

创建子线程后,子线程任务完成并到达pthread_exit()语句但父级仍未到达语句pthread_join()以收集子级的状态。

但不知何故,最后,我能够获得父线程中线程的状态。

如何可能,请帮助我?

1 个答案:

答案 0 :(得分:0)

  

那么,是否意味着pthread_exit()将处于等待状态,直到   父母收集身份?

pthread_exit()结束;线程不是处于等待状态,而是 a"僵尸线程" ,如此note

       Failure to join with a thread that is joinable (i.e., one that is not
       detached), produces a "zombie thread".  Avoid doing this, since each
       zombie thread consumes some system resources, and when enough zombie
       threads have accumulated, it will no longer be possible to create new
       threads (or processes).

retval存储在pthread_t缓冲区内。)