pthread_detach与pthread_join区别
来源:互联网 发布:万象ol怎么清除数据库 编辑:程序博客网 时间:2024/05/21 22:40
创建一个线程默认的状态是joinable, 如果一个线程结束运行但没有被join,则它的状态类似于进程中的Zombie Process,即还有一部分资源没有被回收(退出状态码),所以创建线程者应该调用pthread_join来等待线程运行结束,并可得到线程的退出代码,回收其资源(类似于wait,waitpid) 但是调用pthread_join(pthread_id)后,如果该线程没有运行结束,调用者会被阻塞,在有些情况下我们并不希望如此,比如 在Web服务器中当主线程为每个新来的链接创建一个子线程进行处理的时候,主线程并不希望因为调用pthread_join而阻塞(因为还要继续处理之后到来的链接),这时可以在子线程中加入代码 pthread_detach(pthread_self()) 或者父线程调用 pthread_detach(thread_id)(非阻塞,可立即返回)
这将该子线程的状态设置为detached,则该线程运行结束后会自动释放所有资源。
阅读全文
0 0
- pthread_detach与pthread_join区别
- [pthread] pthread_join 与 pthread_detach
- pthread_join和pthread_detach的区别
- pthread_join与pthread_detach细节问题
- pthread_join与pthread_detach细节问题
- pthread_join与pthread_detach细节问题
- pthread_join与pthread_detach细节问题
- pthread_join与pthread_detach细节问题
- pthread_join与pthread_detach详解(转)
- pthread_join与pthread_detach细节问题
- APUE-线程及其属性:pthread_join与pthread_detach
- 简析pthread_join()和pthread_detach()
- pthread_join pthread_exit pthread_detach
- pthread_join和pthread_detach详解
- 简析pthread_join()和pthread_detach()
- pthread_join和pthread_detach详解
- pthread_join和pthread_detach详解
- pthread_join和pthread_detach详解
- Android ViewGroup事件分发机制
- linux知识学习,总结常用
- linux下tcp客户端能建立多少个长连接
- AndroidUtils(五)Android图片压缩、旋转工具
- 使用Profiler工具分析内存占用情况
- pthread_detach与pthread_join区别
- 树莓派 Unable to open SPI device: Too many open files 问题解决
- Vue系列:如何将百度地图包装成Vue的组件
- Sublime Text3 必要插件及组件
- 外网访问家庭局域网方案,解决运营商100.x.x.xIP问题
- 方法引用
- 逻辑回归:损失函数与梯度下降
- leetcode492. Construct the Rectangle
- 支持表情存储,修改mysql数据库字符集utf8mb4方式