Thread: Correct Termination Of A Thread

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    41

    Post Correct Termination Of A Thread

    Good day everyone. I have a general question relating to threads and the necessary steps to correctly "shutdown" a thread.

    Just quick pseudocode:

    Code:
    HANDLE thread;
    
    thread = CreateThread(task1);
    
    WaitForSingleObject(thread);
    
    closeHandle(thread);    <-------- 
    
    thread = CreateThread(task2);
    
    
    DWORD task1() <--- Thread routine 1.
    DWORD task2() <--- Thread routine 2.
    The line pointed to by the red arrow. Is this required before using the same handle object to create another thread? Or can this call be omitted and just called once upon program termination? Basically wondering about the leaking of GDI resources.

    Thanks.

    Oh I was also wondering. I am quite often shutting down the thread and re-creating it using another processing routine. (Note: Each processing routine does not run in parallel) Should I constantly be shutting down the thread and creating it or just have multiple threads that never shutdown (just suspend) one for each routine or just try and use the one thread to try and handle all routines in there so it lasts the lifetime of the program.? Sorry if this question sounds confusing.
    Last edited by HyperShadow; 07-13-2007 at 12:56 PM. Reason: Additional Question

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Terminating secondary thread from another thread
    By wssoh85 in forum C++ Programming
    Replies: 13
    Last Post: 12-19-2008, 05:14 AM
  2. Messaging Between Threads, Exiting Thread On Demand, Etc.
    By HyperShadow in forum C++ Programming
    Replies: 10
    Last Post: 06-09-2007, 01:04 PM
  3. Thread Synchronization in Win32
    By passionate_guy in forum C Programming
    Replies: 0
    Last Post: 02-06-2006, 05:34 AM
  4. Thread confusion
    By pyrolink in forum C Programming
    Replies: 0
    Last Post: 01-29-2006, 09:42 PM
  5. Thread inside a thread ?
    By lsme in forum Linux Programming
    Replies: 3
    Last Post: 12-08-2004, 11:08 PM