[Asio] when stopping io_service, I get a system_error : mutex: invalid argument

Hello, I'm using asio for a udp receiver. I used the example code from http://www.boost.org/doc/libs/1_40_0/doc/html/boost_asio/example/multicast/r... and created a class that in its contructor opens a socket, binds to it, calls async_receive_from, and in the receive handler again calls async_receive from. Now i have manager class that takes care of the io service, the thread, and an instance of the receiver class. Everything works fine until the moment I destroy the manager class. Here is what the destructor looks like: Manager::~Manager { // first, make sure that no further requests are handled that would prevent io_service from quitting m_receiver->getSock()->shutdown(boost::asio::ip::udp::socket::shutdown_both); m_receiver->getSock()->close(); // destroy the receiver by resetting its auto_ptr m_receiver.reset(); // reset the work auto_ptr, destroying the work for io_service, so that it can quit m_io_work.reset(0); // join the thread in which io_service.run() was called. m_receiver_thread.join(); // now stop the io // this line is commented, it has no effect whether i remove the slashes // m_io_service.stop(); } When I destroy the manager, i get the following error: "terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception::detail::error_info_injector<boost::system::system_error> > ' what(): mutex: Invalid argument" It seems similar to the problem that was discussed here: http://lists.boost.org/Archives/boost/2008/03/134169.php But I'm pretty sure that given I destroy the instance that holds the socket first, the io_service has no work left. I tried catching the exception within the destructor and within the run() of the thread, but no luck. I cannot find the place where the exception is thrown, nor do I have an idea what else to do to ensure the io_service has no work left. Any help on fixing this is greatly appreciated. Regards, Philipp ________________________________________________________________ Neu: WEB.DE Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate für nur 19,99 Euro/mtl.!* http://produkte.web.de/go/02/
participants (1)
-
philipp_muenzel@web.de