[英]How can I determine if a Win32 thread has terminated?
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
}
您鏈接的文檔警告不要使用STILL_ACTIVE
作為返回代碼,因為它無法與用於指示活動線程的返回值區分開來。 因此,不要將它用作返回值,您將不會遇到此問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.