join equivalent in Windows
15,559
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
}
Related videos on Youtube
Author by
kakush
Updated on June 27, 2022Comments
-
kakush almost 2 years
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.
-
Martin James almost 12 years<spiceGirls> Is that what you want, what you really, really want? </spiceGirls> Try hard to not do this at all. Use thread pools or lifetime-of-app threads that loop and never terminate. Waiting for thread termination should be a last resort, used only when no other design approach can possibly work.
-