Boost logo

Boost Users :

Subject: [Boost-users] [Asio] when stopping io_service, I get a system_error : mutex: invalid argument
From: philipp_muenzel_at_[hidden]
Date: 2009-10-03 15:12:33


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/receiver.cpp 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/


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