Boost logo

Boost Users :

Subject: Re: [Boost-users] ASIO Win32 Thread not terminated
From: Manuel Drews (manuel.drews_at_[hidden])
Date: 2010-09-16 04:52:10


Hi Igor, Michi,

-------- Original-Nachricht --------
> Datum: Wed, 15 Sep 2010 16:14:20 +0200
> Von: michi7x7 <mailing-lists_at_[hidden]>
> An: boost-users_at_[hidden]
> Betreff: Re: [Boost-users] ASIO Win32 Thread not terminated

> Hi manuel,
>
> > You're right, the number of threads doesn't increase when I create more
> clients.
> > Still, I'd like to know when these threads terminate. Do they
> nescessarily run until the app exits, or is there a way of telling asio 'hey, I'm
> done with sockets now, no need to keep these threads running'.
> >
> i think the threads are terminated when the destructor of the io_service
> is called. Creating threads is too expensive, to kill them everytime the
> program is idle. So they are usually left in a blocked state.
> You can try this by putting an iostream into brackets {} and set a
> breakpoint afterwards.

yes, that's what I thought, too. But in the example, the whole code is already in {} (the try block) and the threads are still there when reaching the return statement at the end of main (even if I give them time to finish by using a sleep or a for-loop).
I also get the same behaviour if I change the main function like that:

  boost::asio::io_service* io_service = new boost::asio::io_service;
  try
  {
    client c( *io_service, "localhost", "80" );
    client c2( *io_service, "www.heise.de", "80" );
    client c4( *io_service, "www.google.de", "80" );
    io_service->run();
  }
  catch (std::exception& e)
  {
    std::cout << "Exception: " << e.what() << "\n";
  }
  delete io_service;
  // sleep or for-loop here changes nothing
  return 0;
}

-> still two additional threads running here.

Anyway, thanx for your help!

best

Manuel

>
> If the threads are still running, they might be killed using an old
> C-technique, called atexit().
>
> Regards, michi7x7
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users

-- 
Neu: GMX De-Mail - Einfach wie E-Mail, sicher wie ein Brief!  
Jetzt De-Mail-Adresse reservieren: http://portal.gmx.net/de/go/demail

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net