linux线程中pthread_detach函数的作用
来源:互联网 发布:十二星相 知乎 编辑:程序博客网 时间:2024/05/16 09:50
http://mxjloveyou.blog.163.com/blog/static/176254689201232010480203/
linux线程执行和windows不同,pthread有两种状态joinable状态和unjoinable状态,
如果线程是joinable状态,当线程函数自己返回退出时或pthread_exit时都不会释放线程所占用堆栈和线程描述符(总计8K多)。只有当你调用了pthread_join之后这些资源才会被释放。若是unjoinable状态的线程,这些资源在线程函数退出时或pthread_exit时自动会被释放。
unjoinable属性可以在pthread_create时指定,或在线程创建后在线程中pthread_detach自己,如:pthread_detach(pthread_self()),将状态改为unjoinable状态,确保资源的释放。或者将线程置为 joinable,然后适时调用pthread_join.
其实简单的说就是在线程函数头加上 pthread_detach(pthread_self())的话,线程状态改变,在函数尾部直接 pthread_exit线程就会自动退出。省去了给线程擦屁股的麻烦.
http://blog.csdn.net/Lethe1989/archive/2010/01/14/5191165.aspx
- linux线程中pthread_detach函数的作用
- Linux线程中pthread_join和pthread_detach函数
- 线程函数 pthread_detach()
- 【线程】pthread_detach函数解析
- Linux--线程,pthread_detach使用
- pthread_detach(pthread_self())的作用
- pthread_detach的作用
- pthread_join和pthread_detach的作用
- pthread_join和pthread_detach的作用
- linux线程之pthread_join和pthread_detach
- pthread_testcancel,pthread_cleanup_push,pthread_cleanup_pop,pthread_detach(pthread_self())的作用
- pthread_detach()函数
- pthread_detach()函数
- pthread_detach()函数
- pthread_detach()函数
- pthread_detach函数
- linux进程退出,线程资源用pthread_detach释放
- 线程分离:pthread_detach
- eclipse 配置Maven问题解决办法:新建maven工程时报错:Could not resolve archetype org.apache.maven.archetypes .
- H264码率控制简介
- diaos程序员的逆袭之路
- RFC1321(The MD5 Message-Digest Algorithm)中文版
- ARM之GIC中断控制器
- linux线程中pthread_detach函数的作用
- php5以上一次执行多条SQL语句
- OCP 1Z0-053 Q189 -- 启用自动 PGA 内存管理
- OCP-1Z0-052-V8.02-61题
- github使用教程
- Android webkit对于网络传入的数据流解码分析
- unity3d学习笔记(六)--单例脚本和单例类
- java加密解密研究4、UrlBase64算法
- 关于StringIndexOutOfBoundsException那些事~