多次加入同一个 pthread
joining the same pthread multiple times
我程序中的流程调用 pthread_join(thread_id, nullptr);
来自同一调用线程的相同 thread_id
的 2 次。
第一次调用 returns 成功,但第二次它只是无限期地挂起。文档没有说清楚禁止对同一个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.
link 中还有很多关于加入线程(以及其他方面,如果您搜索其他一些 pthread 函数)的其他有用信息。
我程序中的流程调用 pthread_join(thread_id, nullptr);
来自同一调用线程的相同 thread_id
的 2 次。
第一次调用 returns 成功,但第二次它只是无限期地挂起。文档没有说清楚禁止对同一个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.
link 中还有很多关于加入线程(以及其他方面,如果您搜索其他一些 pthread 函数)的其他有用信息。