D
David student
Guest
Hi,
I am seeing some contradictory answers on parent and child thread relationship
I have seen the below statements:
1.
There is no parent/child relationship between threads. If thread A creates thread B and then thread A terminates, then thread B will continue to execute.
The exception to this is when the main thread (that is, the thread that runs the main() function) terminates. When this happens, the process terminates and all other threads stop.
Here terminating main() function means when returning from the main function it kills all the child running threads and finally process also terminates.
2.
I have a Win32 native VC++ application that upon entering WinMain() starts a separate thread.
This thread does some useful job when it is running, then simply exits WinMain() - the other thread is not explicitly stopped
Here we need to stop all the threads prior to exiting otherwise your application may hang.
3.
What happens when an exception goes Unhandled in a multithreaded C++11 program?
If I have VC++ application running two threads, and one of them throws an Unhandled exception, then the entire process will terminate.
From the above statements i understood that
Normally to exit each thread, from ThreadProc we should use ExitThread or Terminate Thread.
But if there is any Unhandled exception in one of the ThreadProc functions, all the threads and process will terminate.
Please help me to understand parent and child thread relationship.
Continue reading...
I am seeing some contradictory answers on parent and child thread relationship
I have seen the below statements:
1.
There is no parent/child relationship between threads. If thread A creates thread B and then thread A terminates, then thread B will continue to execute.
The exception to this is when the main thread (that is, the thread that runs the main() function) terminates. When this happens, the process terminates and all other threads stop.
Here terminating main() function means when returning from the main function it kills all the child running threads and finally process also terminates.
2.
I have a Win32 native VC++ application that upon entering WinMain() starts a separate thread.
This thread does some useful job when it is running, then simply exits WinMain() - the other thread is not explicitly stopped
Here we need to stop all the threads prior to exiting otherwise your application may hang.
3.
What happens when an exception goes Unhandled in a multithreaded C++11 program?
If I have VC++ application running two threads, and one of them throws an Unhandled exception, then the entire process will terminate.
From the above statements i understood that
Normally to exit each thread, from ThreadProc we should use ExitThread or Terminate Thread.
But if there is any Unhandled exception in one of the ThreadProc functions, all the threads and process will terminate.
Please help me to understand parent and child thread relationship.
Continue reading...