你是否正在寻找关于terminatethread的内容?让我把最实用的东西奉献给你:
当前位置:我的异常网» VC/MFC»terminatethread解决办法
terminatethread解决办法
网友分享于:2013-05-21浏览:254次
terminatethread
用terminatethread(m_pThread->m_hThread,0);终止线程时,提示有泄漏.为什么啊???
提示如下:
Detected memory leaks!
Dumping objects ->
thrdcore.cpp(166) : {79} client block at 0x012B1330, subtype 0, 112 bytes long.
a CWinThread object at $012B1330, 112 bytes long
Object dump complete.
只是一个测试的线程,线程中没有分配内存.
------解决方案--------------------
操作线程如果这样操作,一般都有泄漏的,这是强制的把一个正在运行的线程给终止;
好的方法是,让线程执行完后自己消失
------解决方案--------------------
terminatethread is used to cause a thread to exit. When this occurs, the target thread has no chance to execute any user-mode code and its initial stack is not deallocated. DLLs attached to the thread are not notified that the thread is terminating.
外部强制关闭,没机会释放啊。
------解决方案--------------------
代码这样
Handle m_h=CreateThread();
..
closeHandle(m_h);
这样线程执行完后,会自动消失
------解决方案--------------------
你可以程里造个循环,如
void Proc()
{
while (g_bProc)
{
while(***&&g_bproc==true)
{
你想执行的代码1
}
while(***&&g_bproc==true)
{
你想执行的代码2
}
}
}
你在外面改变 g_bProc 这个全局变量就可以结束线程了,。
------解决方案--------------------
Terminate之后CloseHandle
------解决方案--------------------
上面while是用来做循环做一件事的,如果你不需要循环可改用if
以上就是关于terminatethread的全部内容,相信你一定会非常满意。
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/ruanjian/article-11009-1.html
为国牺牲为民族尊严战斗
呵呵