簡體   English   中英

如何確定Win32線程是否已終止?

[英]How can I determine if a Win32 thread has terminated?

如何確定Win32線程是否已終止?

GetExitCodeThread的文檔警告不要因為這個原因使用它,因為出於其他原因可以返回錯誤代碼STILL_ACTIVE。

謝謝您的幫助! :)

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM