CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Guest

    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.


  2. #2
    Join Date
    Jun 1999
    Posts
    143

    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured