Boost logo

Boost Users :

Subject: Re: [Boost-users] Asio io_service::work destructor throwing mutex exception
From: Boris Schaeling (boris_at_[hidden])
Date: 2009-12-13 09:21:41

On Sat, 12 Dec 2009 23:48:57 +0100, Florian Turck <mail_at_[hidden]>

> I am using asio´s io_service::work class to prevent
> 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();


> ioService.stop();
> ioThread.join();
> [...]


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at