Thread: Problem : Threads WILL NOT DIE!!

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    114

    Exclamation Problem : Threads WILL NOT DIE!!

    ok here's the situation

    - i made a program that spawns a worker type thread ( thread A)
    This thread sprawns 20 child worker threads (thread A_1, thread A_2 ...)
    - thread A dies only after all the 20 child threads have returned
    - Before all the threads return, the main user interface thread returns so that the prog is still responsive to the user.

    the threads spawn as they should and according th VC++ debugger, they die properly when the child threads returns
    Code:
    The thread 0xFFF950A5 has exited with code 202 (0xCA).
    The thread 0xFFF95485 has exited with code 202 (0xCA).
    The thread 0xFFFA8865 has exited with code 202 (0xCA).
    The thread 0xFFF96F81 has exited with code 202 (0xCA).
    The thread 0xFFFAD82D has exited with code 202 (0xCA).
    The thread 0xFFF8BDA9 has exited with code 202 (0xCA).
    The thread 0xFFF90001 has exited with code 202 (0xCA).
    The thread 0xFFF8D5C5 has exited with code 202 (0xCA).
    The thread 0xFFF949FD has exited with code 202 (0xCA).
    The thread 0xFFF94441 has exited with code 202 (0xCA).
    The thread 0xFFF8B1C5 has exited with code 202 (0xCA).
    The thread 0xFFFABD21 has exited with code 202 (0xCA).
    The thread 0xFFF89D69 has exited with code 202 (0xCA).
    The thread 0xFFF971F1 has exited with code 202 (0xCA).
    The thread 0xFFF80095 has exited with code 202 (0xCA).
    The thread 0xFFFECBAD has exited with code 202 (0xCA).
    The thread 0xFFF95BF1 has exited with code 202 (0xCA).
    The thread 0xFFFC1E59 has exited with code 202 (0xCA).
    The thread 0xFFFFE325 has exited with code 202 (0xCA).
    The thread 0xFFF98609 has exited with code 202 (0xCA).
    The thread 0xFFF9BF8D has exited with code 202 (0xCA).
    The thread 0xFFF972A9 has exited with code 1 (0x1).  <== thread A
    however i ran another program ( Iarsn TaskInfo2003 from download.com) to check out if the threads have died and HORRORS OF HORRORS!!

    they were still alive, increasing in Arimetic progression everytime i press the button. Hence the more i use the program, the more UNDEAD threads there are hogging system resources.
    So... how do i solve this stubbon problem??

    - terminatethread isnt that elegant coz it doesnt flush everything out
    - closehandle??
    - exitthread?? I thought the child threads returns it's remaments memory is cleaned up cleaner than using exitthread?


    I am using
    - win98SE
    - VC++ 6.0
    - API style of coding, dunnno anything about MFC.(learning the basic API before going to MFC)

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> - closehandle??
    If you're not closing the thread's handle once it's done....shame on you!

    Here is a nice and simple Win32 thread wrapper class you might find usefull.

    gg

  3. #3
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    nextmap

    (sorry)
    .sect signature

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Closing threads
    By VirtualAce in forum Windows Programming
    Replies: 8
    Last Post: 01-02-2006, 10:49 AM
  2. Forks v's threads
    By clancyPC in forum C Programming
    Replies: 7
    Last Post: 11-11-2005, 06:29 AM
  3. 1337 bible, Gen 11
    By Paz_Rax in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 05-20-2005, 09:40 PM