您的位置:首页 > 其它

_beginthreadex和_beginthread区别,调用_endthread不会析构局部变量??

2015-09-01 20:52 337 查看
2._beginthreadex和_beginthread区别

_beginthreadex内部会自动调用 _endthreadex.

_beginthread内部会自动调用_endthread.

_endthread内部会自动调用CloseHandle关闭当前Thread内核对象的句柄,所以在用_beginthread 时我们不需要在主线程中调用CloseHandle来关闭子线程的句柄。

_endthreadex相比_endthread而言更安全。它不会自动关闭当前Thread内核对象的句柄。所以在用_beginthreadex时我们需要用CloseHandle来关闭子线程的句柄。
http://blog.sina.com.cn/s/blog_9635e5ef0101psgk.html
void CJtDevcieSearch::Static_StartReceiveThread(void *arg)

{

CJtDevcieSearch *self = (CJtDevcieSearch *)arg;

std::tr1::shared_ptr<CJtDevcieSearch> m_TmpSelf = self->m_Self;

long use_count = m_TmpSelf.use_count();

self->m_Self.reset();

use_count = m_TmpSelf.use_count();

m_TmpSelf->StartReceiveThread();

//_endthread(); //注意,如该行不注释掉,m_TmpSelf得不到释放

use_count = m_TmpSelf.use_count();

return;

}

上面是一个由_beginthread创建的线程,如果运行了_endthread();那么m_TmpSelf 得不到释放,还未深究,由谁知道原因吗????
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: