linux线程中pthread_detach函数的作用

来源:互联网 发布:十二星相 知乎 编辑:程序博客网 时间:2024/05/16 09:50

http://mxjloveyou.blog.163.com/blog/static/176254689201232010480203/

linux线行和windows不同,pthread有两joinableunjoinable

如果线程是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

 

原创粉丝点击