Windows C ++ - 关闭线程与CloseHandle [英] Windows C++ - closing thread with CloseHandle

查看:431
本文介绍了Windows C ++ - 关闭线程与CloseHandle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过CreateThread函数创建了一个线程。

I have created a thread by the "CreateThread" function.

在这个线程,我有一个'while(true)'循环

in this thread, I have a 'while(true)' loop (that reads input).

现在,当我想关闭该线程时,我使用了CloseHandle函数。

for now, when I want to close the thread, I use the 'CloseHandle' function.

这是正确的事情吗?或者我应该退出'while(true)'循环然后使用'CloseHandle'函数?

Is this the right thing to do? Or I should exit the 'while(true)' loop and then use the 'CloseHandle' function?

谢谢

推荐答案

CloseHandle()不会销毁,终止或支配线程,它只会销毁句柄本身(所以你没有一个句柄来杀死线程或等待它) 。线程继续正常工作(我在许多情况下使用了它),并且停止它的唯一方法是退出线程函数(ThreadProc()),或者杀死它。

CloseHandle() does not destroy, terminate or supspend the thread, it only destroys the handle itself (so then you don't have a handle to kill the thread or wait on it). The thread continues to work normally (I have utilised this in numerous cases), and the only way to stop it is either exit the thread function (ThreadProc()), or kill it.

这篇关于Windows C ++ - 关闭线程与CloseHandle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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