[英]How can I determine if a Win32 thread has terminated?
How can I determine if a Win32 thread has terminated? 如何确定Win32线程是否已终止?
The documentation for GetExitCodeThread warns to not to use it for this reason since the error code STILL_ACTIVE can be returned for other reasons. GetExitCodeThread的文档警告不要因为这个原因使用它,因为出于其他原因可以返回错误代码STILL_ACTIVE。
Thanks for the help! 谢谢您的帮助! :)
:)
MSDN mentions that "When a thread terminates, the thread object attains a signaled state, satisfying any threads that were waiting on the object". MSDN提到“当线程终止时,线程对象获得信号状态,满足任何等待对象的线程”。
So, you can check for whether a thread has terminated by checking the state of the thread handle - whether it's signaled or not: 因此,您可以通过检查线程句柄的状态来检查线程是否已终止 - 是否已发出信号:
DWORD result = WaitForSingleObject( hThread, 0);
if (result == WAIT_OBJECT_0) {
// the thread handle is signaled - the thread has terminated
}
else {
// the thread handle is not signaled - the thread is still alive
}
The documentation you link to warns against using STILL_ACTIVE
as a return code, since it can't be distinguished from the return value used to indicate an active thread. 您链接的文档警告不要使用
STILL_ACTIVE
作为返回代码,因为它无法与用于指示活动线程的返回值区分开来。 So don't use it as a return value and you won't have this problem. 因此,不要将它用作返回值,您将不会遇到此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.