Boost logo

Boost Users :

Subject: Re: [Boost-users] Thread_group semantics
From: Kenneth Adam Miller (kennethadammiller_at_[hidden])
Date: 2014-01-13 20:05:13


Yeah, but I want to be able to create a thread_pool in the creating thread
and then move on, posting work to it whenever. In your shutdown
descriptions for the first way to do it, you seem to describe no way to
make sure that all work posted to it gets completed.

I haven't read all of asio's documentation yet. I will though, it's on my
list.

On Mon, Jan 13, 2014 at 6:51 PM, Gavin Lambert <gavinl_at_[hidden]>wrote:

> On 14/01/2014 13:26, Quoth Kenneth Adam Miller:
>
> Would it work better if it was threads.join_all() then ioServices.stop()?
>>
>
> No, that would make it block forever.
>
> You must do one of the following:
>
> 1. create an io_service.
> 2. create an io_service::work.
> 3. create threads for your thread_group.
> 4. at any time after this, post work to the service.
> 5a. only on shutdown, call stop() and join_all(), in that order. Note
> that this may result in some posted work not getting called, and therefore
> some resources not cleaned up.
> 5b. OR instead of calling stop(), destroy the io_service::work you created
> earlier (and if you're using ASIO async operations, you must also cancel or
> close anything outstanding that you don't want to wait for), and then call
> join_all(). this will block until all posted work is completed.
>
> OR
>
> 1. create an io_service.
> 2. post work to the service. (can only be done here, or from inside a
> callback called by the service)
> 3. create threads for your thread_group.
> 4. call join_all(), which will block until all pending work is done.
>
>
> The former lets you make a threadpool you can keep around for the life of
> your app, and post work as desired. The latter lets you make a threadpool
> to execute a single blocking task with multiple concurrent subtasks.
>
> (Other variations are possible of course but the order of the above is
> important.)
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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