linux下多线程 之 pthread_detach(pthread_self())
来源:互联网 发布:qt snmp 网络管理软件 编辑:程序博客网 时间:2024/06/14 18:16
多线程稍微看了下还能接受没想象中的难,写了个示例程序运行修改运行修改几遍后也大致明白了。
写个碰到的问题,记录下自己的技术之路点滴
pthread_detach(pthread_self())
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.
摘自 http://kb.cnblogs.com/a/1285801/
其实简单的说就是在线程函数头加上 pthread_detach(pthread_self())的话,线程状态改变,在函数尾部直接pthread_exit线程就会自动退出。省去了给线程擦屁股的麻烦
本文转自:http://blog.csdn.net/lethe1989/article/details/5191165
- linux下多线程 之 pthread_detach(pthread_self())
- linux下多线程 之 pthread_detach(pthread_self())
- linux下多线程 之 pthread_detach(pthread_self())
- linux下多线程 之 pthread_detach(pthread_self())
- linux下多线程 之 pthread_detach(pthread_self())
- linux下多线程 之 pthread_detach(pthread_self())
- linux下多线程之pthread_detach(pthread_self())
- linux下多线程之pthread_detach(pthread_self())
- linux下多线程之pthread_detach(pthread_self())
- linux下多线程之pthread_detach(pthread_self())
- linux下多线程之pthread_detach(pthread_self())
- linux下多线程之pthread_detach(pthread_self())
- linux下多线程之pthread_detach(pthread_self())
- [转]linux下多线程之pthread_detach(pthread_self())
- linux下多线程之pthread_detach(pthread_self())
- linux下多线程之pthread_detach(pthread_self())
- pthread_detach(pthread_self())
- 多线程函数系列pthread_create(), pthread_join(), pthread_self(),pthread_exit(), pthread_detach()实例详解
- CSDN 上的图片显示不出
- Ubuntu下创建SD卡分区的问题
- log4j 与 logback 性能对比
- android listview checkbox
- 随笔一则
- linux下多线程 之 pthread_detach(pthread_self())
- vs快捷键(开发助手)
- eclipse下查看android源码
- How To Successfully Change Your Career
- [技术]使用NSOperationQueue简化多线程开发
- 把txt文件保存了表格形式并存放到BMP文件
- 代码审查:大家都应该做的事情
- 精妙SQL語句
- getopt_long(argc, argv, "", OPTIONS, NULL)分析