Boost logo

Boost Users :

Subject: [Boost-users] Asio io_service::work destructor throwing mutex exception
From: Florian Turck (mail_at_[hidden])
Date: 2009-12-12 17:48:57


Hi,

I am using asio´s io_service::work class to prevent io_service.run()
from returning. Unfortunatly on deletion of my object the destructor of
io_service::work throws an exception:

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

Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 libSystem.B.dylib 0x9578c732 __kill + 10
1 libSystem.B.dylib 0x9578c724 kill$UNIX2003 + 32
2 libSystem.B.dylib 0x9581f98d raise + 26
3 libSystem.B.dylib 0x95835a44 abort + 93
4 libstdc++.6.dylib 0x9122afda
__gnu_cxx::__verbose_terminate_handler() + 433
5 libstdc++.6.dylib 0x9122917a
__cxxabiv1::__terminate(void (*)()) + 10
6 libstdc++.6.dylib 0x9122851d __cxa_call_terminate + 53
7 libstdc++.6.dylib 0x9122909d __gxx_personality_v0 + 911
8 libSystem.B.dylib 0x9579aa9d unwind_phase2 + 205
9 libSystem.B.dylib 0x957b1fd9 _Unwind_Resume + 73
10 com.yourcompany.ReclaimR 0x00026ed3
boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>::scoped_lock(boost::asio::detail::posix_mutex&)
+ 79 (scoped_lock.hpp:37)
11 com.yourcompany.ReclaimR 0x00027dfa
boost::asio::detail::task_io_service<boost::asio::detail::kqueue_reactor<false>
>::work_finished() + 28 (task_io_service.hpp:171)
12 com.yourcompany.ReclaimR 0x00027e72
boost::asio::io_service::work::~work() + 22 (io_service.ipp:155)

The asio related objects are all members of my class:

[...]
private:

        io_service ioService;
        io_service::work ioWork;
        thread ioThread;
        tcp::socket controlSocket;
        tcp::acceptor acceptor;
[...]

This is how I initialize everything:

[...]
MyClass() : ioService(),
                ioWork(ioService),
                ioThread(bind(&io_service::run, &ioService)),
                controlSocket(ioService),
                acceptor(ioService),
[...]

Finally this is what happens in the destructor:

[...]
if (connected)
        disconnect();
ioService.stop();
ioThread.join();
[...]

Anyone knows how to deal with this?

Regards,

Florian


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