简体   繁体   English

pthread线程状态

[英]pthread thread state

Is there a mechanism that I can use to tell if a pthread thread is currently running, or has exited? 是否可以使用某种机制来判断pthread线程当前正在运行还是已退出? Is there a method for pthread_join() that is able to timeout after a specific period of time if the thread has not yet exited? 是否存在pthread_join()的方法,如果线程尚未退出,该方法可以在特定时间段后超时?

If you're only targeting linux, use http://www.kernel.org/doc/man-pages/online/pages/man3/pthread_tryjoin_np.3.html 如果您仅针对Linux,请使用http://www.kernel.org/doc/man-pages/online/pages/man3/pthread_tryjoin_np.3.html

If you need something for any POSIX system, you can copy the "pthread_timedjoin" implementation in http://www.opengroup.org/onlinepubs/000095399/xrat/xsh_chap02.html#tag_03_02_08_21 - which uses a condition variable to signal thread termination, and pthread_cond_timedwait for the timeout. 如果您需要任何POSIX系统的东西,则可以在http://www.opengroup.org/onlinepubs/000095399/xrat/xsh_chap02.html#tag_03_02_08_21中复制“ pthread_timedjoin”实现,该实现使用条件变量来表示线程终止,和pthread_cond_timedwait等待超时。

我刚结束将线程包装在C ++类中,并保留状态变量,以后可以检查该变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM