_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 得不到释放,还未深究,由谁知道原因吗????
_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 得不到释放,还未深究,由谁知道原因吗????
相关文章推荐
- spring的@ModelAttribute作用
- 字符串同构的最小表示方法
- javascript 之闭包
- 找出单链表的倒数第K个(从1开始计数)结点的值
- Hibernate知识点汇总
- OpenCV2:Mat
- 31 Next Permutation
- 杭电OJ-2032_杨辉三角
- jquery中的多条件选择,相对选择和层次选择
- UGUI基本控件(二)
- Android问题集(二)——TextView在点击时显示不同颜色,Button点击效果
- ImageJ二次开发学习纪录之初步体会
- 反转一个链表并输出各个结点的值
- oracle查看表占用磁盘空间
- 省市联动
- ajax异步请求
- Spring AOP 静态代理与动态代理
- POJ 1741 Tree(树分治)
- JavaWeb笔记——ajax异步请求
- #pragma 预处理指令详解