Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 是否可以在c++;?_C++_Multithreading_Join_Boost - Fatal编程技术网

C++ 是否可以在c++;?

C++ 是否可以在c++;?,c++,multithreading,join,boost,C++,Multithreading,Join,Boost,案例如下:我有一个主进程,让我们假设pid=1。主进程创建具有相同pid和不同线程ID的子线程。我希望在不阻塞主线程的情况下加入子线程,因此我从主进程创建了一个新线程,并尝试在那里加入子线程,但没有成功。我想知道,是否可以在新创建的线程中加入子线程,或者它必须是主进程?至少在linux上(使用pthreads),这应该是可能的。引用文件: All of the threads in a process are peers: any thread can join with any other t

案例如下:我有一个主进程,让我们假设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上这样做。

没有“子线程”这样的东西。线程没有父/子关系。除了
main
线程外,每个线程都是在另一个线程中创建的。它定义了一个有向无环图,确切地说是一个树(因为一个线程不能由两个线程创建)。因此,创建定义了父/子关系。它们更像克隆体,而不是后代。main()由OS加载器创建的线程运行。它在Linux中经过测试并正常工作,我还必须在Windows上尝试。