Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【每日一题】-2019-12-1-高并发服务器 线程属性采用join好还是detach好? #35

Open
watchpoints opened this issue Dec 1, 2019 · 1 comment
Labels
Operating System 操作系统

Comments

@watchpoints
Copy link
Contributor

watchpoints commented Dec 1, 2019

//只要线程执行pthread_exit(),整个线程就会结束,并且释放占用资源,
为什么还要区分detach模式呢,
//感觉没有任何区别呀,高性能服务器 你们一般采用哪个方式

脉脉

@watchpoints watchpoints added the Operating System 操作系统 label Dec 1, 2019
@watchpoints
Copy link
Contributor Author

watchpoints commented Dec 1, 2019

回答:
如果是线程池或者常驻进程 采用join 统一管理,
如果作业类型,detach结束后,不需要进程等待,或者说进程可以自己离开,采用detach

场景1 :类似fork形式 主线程 调用子线程执行job(周期可长可短),main线程调用
pthead_exit() 离开,等待子线程job执行完毕,然后进程在最后推出。必须使用detach

我感觉回答不好,期待你更好的反馈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Operating System 操作系统
Projects
None yet
Development

No branches or pull requests

1 participant