Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

join equivalent in Windows

How do I wait for a thread to die in Windows? This is what I want my code to look like:

main thread:

creating thread: thread1
waiting for thread1 to die
//rest of the code

I am using Win32 API.

like image 464
kakush Avatar asked Aug 02 '12 14:08

kakush


1 Answers

It's easy: the WaitForSingleObject can block current thread given the other thread's handle.

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

   // by now thread #2 is over

}
like image 160
Dmitry Arestov Avatar answered Sep 21 '22 13:09

Dmitry Arestov