Click to See Complete Forum and Search --> : How to terminate a child thread?


August 27th, 1999, 12:11 PM
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.

sqrly
August 30th, 1999, 12:20 PM
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.