Uha*_*all 15 c c++ winapi multithreading
如何确定Win32线程是否已终止?
GetExitCodeThread的文档警告不要因为这个原因使用它,因为出于其他原因可以返回错误代码STILL_ACTIVE.
谢谢您的帮助!:)
Mic*_*urr 36
MSDN提到"当线程终止时,线程对象获得信号状态,满足任何等待对象的线程".
因此,您可以通过检查线程句柄的状态来检查线程是否已终止 - 是否已发出信号:
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
}
Run Code Online (Sandbox Code Playgroud)