|
Boost Users : |
Subject: Re: [Boost-users] Thread_group semantics
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2014-01-13 19:51:25
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 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