gpt4 book ai didi

c++ - pthread_exit() 后多久 pthread_join() 有望成功?

转载 作者:行者123 更新时间:2023-11-30 02:49:26 25 4
gpt4 key购买 nike

我的任务是创建一个用户级线程库来复制 pthread 的功能(完全公开:这是针对操作系统类(class)的)。但是,我不清楚 pthread_join()pthread_exit() 在线程已经退出时如何交互。

特别是,手册页指出:

The pthread_join() function waits for the thread specified by thread to terminate. If that thread has already terminated, then pthread_join() returns immediately.

这是一种保证,即使我创建了数百万个线程,它们的结果仍可用于一次连接吗?否则,我可以期望结果保留多长时间?

我不是在寻求有关如何实现它的建议(这才是最有趣的!),我只是想在开始之前确定行为。

最佳答案

没有时间限制,只要进程本身处于事件状态以使其可用于连接,实现就必须保持“返回值”。

pthread_exit 的 POSIX 定义简单地说:

The pthread_exit() function shall terminate the calling thread and make the value value_ptr available to any successful join with the terminating thread.

加入是在退出之前发起的,还是多年后发起的,或者是只有一个额外的线程还是数百个都无关紧要。

关于c++ - pthread_exit() 后多久 pthread_join() 有望成功?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21179513/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com