Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

static_thread_pool

typedef thread_pool static_thread_pool;
Types

Name

Description

basic_executor_type

Executor implementation type used to submit functions to a thread pool.

executor_type

Executor used to submit functions to a thread pool.

fork_event

Fork-related event notifications.

Member Functions

Name

Description

attach

Attaches the current thread to the pool.

executor

Obtains the executor associated with the pool.

get_executor

Obtains the executor associated with the pool.

join

Joins the threads.

notify_fork

Notify the execution_context of a fork-related event.

stop

Stops the threads.

thread_pool [constructor]

Constructs a pool with an automatically determined number of threads.

Constructs a pool with a specified number of threads.

wait

Waits for threads to complete.

~thread_pool [destructor]

Destructor.

Protected Member Functions

Name

Description

destroy

Destroys all services in the context.

shutdown

Shuts down all services in the context.

The thread pool class is an execution context where functions are permitted to run on one of a fixed number of threads.

Submitting tasks to the pool

To submit functions to the thread pool, use the dispatch, post or defer free functions.

For example:

void my_task()
{
  ...
}

...

// Launch the pool with four threads.
boost::asio::thread_pool pool(4);

// Submit a function to the pool.
boost::asio::post(pool, my_task);

// Submit a lambda object to the pool.
boost::asio::post(pool,
    []()
    {
      ...
    });

// Wait for all tasks in the pool to complete.
pool.join();
Requirements

Header: boost/asio/static_thread_pool.hpp

Convenience header: boost/asio.hpp


PrevUpHomeNext