How to terminate a child thread?
The child thread can exit in three way:
1. It finishes its operation
2. It calls ExitThread
3. Parent calls TerminateThread
I know that TerminateThread is not a good idea since it won't clear the resource (or kernel object) correctly. But my application need to terminate
the child thread by some exception, how can I do that and make sure the resource are clean? Thanks.
Re: How to terminate a child thread?
I use a variable that the thread can get to through the pointer that you pass to the thread function. The main thread sets m_endAllThreads to true, and the worker thread checks this periodically. Then the main thread uses WaitForSingleObject() to give the worker time to finish up.