gpt4 book ai didi

c++ - 是否可以在 C++ 中的新创建线程中加入子线程?

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:42:48 26 4
gpt4 key购买 nike

案例如下:我有一个主进程,假设 pid=1。主进程创建具有相同 pid 和不同线程 id 的子线程。我想在不阻塞主线程的情况下加入子线程,所以我从主进程创建了一个新线程并尝试在那里加入子线程但没有成功。我想知道,是否可以在新创建的线程中加入子线程,还是必须是主进程?

最佳答案

至少在 linux 上(使用 pthreads)它应该是可能的。引用文档:

All of the threads in a process are peers: any thread can join with any other thread in the process.

我想你也可以在 Windows 上做同样的事情。

关于c++ - 是否可以在 C++ 中的新创建线程中加入子线程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26034774/

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