在Windows中加入等效项

kak*_*ush 10 c++ windows winapi multithreading join

如何在Windows中等待线程死?这就是我希望我的代码看起来像:

main thread:

creating thread: thread1
waiting for thread1 to die
//rest of the code
Run Code Online (Sandbox Code Playgroud)

我正在使用Win32 API.

Dmi*_*tov 27

这很简单:WaitForSingleObject可以在给定其他线程句柄的情况下阻止当前线程.

void Thread1Proc()
{
   HANDLE hThread2 = CreateThread(...);
   WaitForSingleObject(hThread2, INFINITE);

   // by now thread #2 is over

}
Run Code Online (Sandbox Code Playgroud)