Thread: thread termination

  1. #1
    ... arjunajay's Avatar
    Join Date
    May 2005

    Question thread termination

    How can I Stop a working thread from the main thread?
    In the main thread I have the HANDLE of the working thread.
    The user has activated WM_CLOSE in the main thread's window and I have to stop this worker thread.
    This worker contains mainly a really long loop which contributes to more than approx:98% of the working thread function's time.
    I checked the documentation and found two functions.
    TerminateThread(). But ExitThread() is called implicitly BY the thread and the documentation says that the latter is very dangerous and should be used sparingly only.

    I am thinking of a global variable(BOOL) to signal the worker thread.
    Can somebody suggest a better way ?
    Thanks in avance.

  2. #2
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    What's wrong with TerminateThread()?

  3. #3
    Registered User
    Join Date
    Nov 2001
    boolean better solution


  4. #4
    ... arjunajay's Avatar
    Join Date
    May 2005

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 02-26-2009, 11:48 PM
  2. Terminating secondary thread from another thread
    By wssoh85 in forum C++ Programming
    Replies: 13
    Last Post: 12-19-2008, 05:14 AM
  3. Thread Prog in C language (seg fault)
    By kumars in forum C Programming
    Replies: 22
    Last Post: 10-09-2008, 01:17 PM
  4. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  5. thread termination
    By JagWire in forum C Programming
    Replies: 2
    Last Post: 07-02-2002, 01:09 PM