开发者

How to know if a pthread died

How can one know if a pthre开发者_JAVA百科ad died?

Is there a way to check a pthreads status?


if(pthread_kill(the_thread, 0) == 0)
{
    /* still running */
}

See: pthread_kill

Note: there is an inherent risk to using pthread_kill() to test if a thread is still running. See this post for an explanation: How do I determine if a pthread is alive?


If you don't need to write a portable application and can use GNU extensions, you can use pthread_tryjoin_np. I believe there isn't another way to do it, except for setting up communication between two threads (e.g. using a global mutex which is hold by a thread as long as it is alive).


I want to add to the discussion the fact that a thread can just die in another case that is not mentioned here in the case of a signal such as SIGPIPE when it is not handled by the hosting process or the thread it self and in situations when such a signal can arise

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜