pthread_detach 是否像 pthread_join 一样等待子进程终止?
我想知道 pthread_detach 会停止父线程直到子线程终止,还是继续执行??...因为, pthread_join 等待子线程完成然后继续...
I wanted to know will pthread_detach halt the parent until the child thread terminates, or it goes on with the execution??... As, the pthread_join waits for the child thread to finish and then proceed...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信 pthread_detach 的目的是表明您不打算在给定线程上调用 pthread_join 。它不会阻塞。您会这样做,因为 pthread 实现需要跟踪线程已终止的事实以及它的退出值,以防稍后 pthread_join。因此,您应该调用 pthread_join 来释放内部数据结构中的该空间,或者调用 pthread_detach 来指示不应保留该空间。
I believe the purpose of pthread_detach is to indicate that you do not intend to call pthread_join on the given thread. It does not block. You would do this because the pthread implementation needs to keep track of the fact that the thread has terminated and what it's exit value is in case of a later pthread_join. So you should either call pthread_join to free that space in the internal data structure, or call pthread_detach to indicate that the space should not be reserved.