Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

std_thread_pool

A very simple thread pool based on std::thread or boost::thread.

Description

This instantiates a asio::io_service and a latchable asio::io_service::work to keep any threads working until the instance is destructed.

Synopsis
class std_thread_pool
      : public thread_source
{
  // ...
};
Constructor(s)

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()
Member Function(s)

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.

Header

#include <boost/afio/v2/afio.hpp>


PrevUpHomeNext