Thread: Closing child threads

  1. #1
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986

    Closing child threads

    In my program I want to use blocking sockets. I was hoping to do this by creating a new thread that can run the blocking accept() call and process connections, while the main thread (which spawned it) waits to be told to quit.

    When the main thread is told to quit, it shuts down the thread it created so that its not accept()ing anymore, closes the socket it was listening on and then shuts the rest of the program.

    A sample would look like this:

    hThread = CreateThread(..);
    if (PeekMessage(.., WM_QUIT, WM_QUIT, ..))
    ExitThread(hThread);

    Unforutunatly I know ExitThread() can only be called by the thread that owns it (or so it seems). My question then becomes, how can I close a thread I just created, from the parent thread?

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Look at the bottom of the ExitThread doc page. You will see in the 'see also' section a link: Process and Thread Functions. Follow the link.

    Have Fun.

  3. #3
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Thanks anontymous, I take it I was looking for the terminateThread() function? I did a test and that seems to work exactly how I want it to, so thanks .

    Why can't they just make ExitThread take a handle to a thread, or NULL for the current thread? Why do they do this on purpose just because they know I'd never search for TerminateThread()?!

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Because Microsoft is evil.

    [puts on flame-resistant suit]
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    [puts on flame-resistant suit]
    ROFL!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  2. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 07:53 AM
  3. Closing threads
    By VirtualAce in forum Windows Programming
    Replies: 8
    Last Post: 01-02-2006, 10:49 AM
  4. Premature closing of threads
    By *ClownPimp* in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 03-07-2003, 11:27 AM
  5. Closing Child Windows
    By minesweeper in forum Windows Programming
    Replies: 5
    Last Post: 07-16-2002, 08:34 AM