thread termination

This is a discussion on thread termination within the Windows Programming forums, part of the Platform Specific Boards category; How can I Stop a working thread from the main thread? In the main thread I have the HANDLE of ...

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

    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.
    ExitThread()
    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
    Location
    Estonia
    Posts
    2,318
    What's wrong with TerminateThread()?

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    boolean better solution

    Kuphryn

  4. #4
    ... arjunajay's Avatar
    Join Date
    May 2005
    Posts
    203
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 02-26-2009, 10:48 PM
  2. Terminating secondary thread from another thread
    By wssoh85 in forum C++ Programming
    Replies: 13
    Last Post: 12-19-2008, 04: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21