
On Sat, 12 Dec 2009 23:48:57 +0100, Florian Turck <mail@florianturck.de> wrote:
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
I always use a dynamically allocated work object and store it in a scoped_ptr. This works fine (I've changed your code below). However I don't remember having read in the Boost.Asio documentation that your approach is wrong. But I don't remember either where I got this idea with the dynamically allocated object from.
[...] private:
io_service ioService; io_service::work ioWork;
boost::scoped_ptr<io_service::work> ioWork;
[...] MyClass() : ioService(), ioWork(ioService),
ioWork(new io_service::work(ioService)),
[...] if (connected) disconnect();
ioWork.reset();
ioService.stop(); ioThread.join(); [...]
HTH, Boris