
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
' 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_lockboost::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 ::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