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.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With