我程序中的流程调用 pthread_join(thread_id, nullptr);
来自同一调用线程的同一 thread_id
两次。
第一次调用成功返回,但第二次它只是无限期地挂起。文档没有说清楚禁止对同一个thread_id多次调用pthread_join。真的是这样吗?
我知道我可以使用 pthread_cond_t 实现线程同步,但我想先了解 pthread_join 的限制。
最佳答案
看看 documentation for pthread_join
- 在注释部分指出:
Joining with a thread that has previously been joined results in undefined behavior.
链接中还有很多关于加入线程(以及其他方面,如果您搜索其他一些 pthread 函数)的其他有用信息。
关于c - 多次加入同一个 pthread,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33245113/