我如何确定一个Win32线程终止? [英] How can I determine if a Win32 thread has terminated?

查看:192
本文介绍了我如何确定一个Win32线程终止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何判断一个Win32线程终止?

How can I determine if a Win32 thread has terminated?

对于 GetExit codeThread <文档/ STRONG>警告不要使用它因为这个原因,因为错误code STILL_ACTIVE可以因其他原因被退回。

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.

感谢您的帮助! :)

推荐答案

MSDN提到,当一个线程终止,线程对象达到一个信号状态,满足了等待的对象,任何线程。

MSDN mentions that "When a thread terminates, the thread object attains a signaled state, satisfying any threads that were waiting on the object".

所以,你可以检查一个线程是否已经通过检查线程处理的状态终止 - 无论是信号还是不:

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
}

这篇关于我如何确定一个Win32线程终止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆