Home | Libraries | People | FAQ | More |
A very simple thread pool based on std::thread or boost::thread.
This instantiates a
and a latchable asio::io_service
to keep any threads working until the instance is destructed.
asio::io_service::work
class std_thread_pool : public thread_source { // ... };
Function |
Description |
Parameters |
---|---|---|
std_thread_pool(size_t no) |
Constructs a thread pool of no workers. |
size_t: no: The number of worker threads to create |
~std_thread_pool() |
Function |
Description |
Parameters |
Returns |
---|---|---|---|
asio::io_service & io_service() |
Returns the underlying io_service. |
||
template<class R> void enqueue(enqueued_task< R > task) |
Sends a task to the thread pool for execution. |
enqueued_task< R >: task: |
|
template<class F> shared_future< typename std::result_of< F()>::type > enqueue(F f) |
Sends some callable entity to the thread pool for execution. |
F: f: Any instance of a callable type |
An enqueued task for the enqueued callable |
void add_workers(size_t no) |
Adds more workers to the thread pool. |
size_t: no: The number of worker threads to add |
|
void destroy() |
Destroys the thread pool, waiting for worker threads to exit beforehand. |
#include <boost/afio/v2/afio.hpp>