Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost] [thread] thread handling question
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2016-06-02 20:39:38


On 2/06/2016 20:07, Markus Pieper wrote:
> Hi, this may be a very dumb question… My boost version is 1.56.0.
>
> In my program I use a database logging technique. To avoid blocking the
> main thread, I coded this:
[...]
> But then, after a long run I get a boost::thread_resource_error
> exception. You may say: Of course, you never join your thread and after
> a few thousands new threads you blow your stack.

For this sort of application, you might want to consider using a
threadpool. You can either use one provided by your target OS API, or
use Boost.Asio.

You can ignore most of the I/O stuff and just use an io_service as a
threadpool manager by giving it an io_service::work so it doesn't stop
until you're done, feed it as many threads as you want to concurrently
run work, and then just post jobs to it whenever something comes up.


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