Pthread Barrier 与 Loop Join
所以我在 C 中的问题是:与在循环中使用 pthread Join 相比,使用 pthread 屏障(init 和 wait 等)基本上有什么区别(也许是优点和缺点)。
假设我在一个循环中创建了 10 个线程,然后在我想要屏障的地方,我放置了一个循环来对所有线程进行 Join。这不也能起到屏障的作用吗?
请澄清。谢谢!
So my question in C is: what is basically the differences (maybe pros and cons) of using a pthread barrier (init and wait..etc) compared to using the pthread Join in a loop.
So say I created 10 threads in a loop, and then later at the place of where I want a barrier, I put a loop to do Join for all the threads. Wouldn't that act as a Barrier too?
Please clarify. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
pthread_join()
阻塞调用线程,直到加入线程退出。相反,屏障允许所有线程继续运行。pthread_join()
blocks the calling thread until the joining thread exits. In contrast, a barrier allows the all threads to continue running.