threadpool | Overview | Reference | Tutorial | Examples | Design

Reference | Class List | Member Functions | Typedefs | File List

Public Types | Public Member Functions
boost::threadpool::thread_pool< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy > Class Template Reference

List of all members.

## Public Types
typedef SchedulingPolicy < task_type > | scheduler_type
typedef SizePolicyController < pool_core_type > | size_controller_type
typedef SizePolicy < pool_core_type > | size_policy_type
typedef Task | task_type
## Public Member Functions
size_t | active () const
void | clear ()
bool | empty () const
size_t | pending () const
bool | schedule (task_type const &task)
size_t | size () const
size_controller_type | size_controller ()
| thread_pool (size_t initial_threads=0)
void | wait (size_t task_threshold=0) const
bool | wait (xtime const &timestamp, size_t task_threshold=0) const

## Detailed Description

### template<typename Task = task_func, template< typename > class SchedulingPolicy = fifo_scheduler, template< typename > class SizePolicy = static_size, template< typename > class SizePolicyController = resize_controller, template< typename > class ShutdownPolicy = wait_for_all_tasks>
class boost::threadpool::thread_pool< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >

Thread pool.

Thread pools are a mechanism for asynchronous and parallel processing within the same process. The pool class provides a convenient way for dispatching asynchronous tasks as functions objects. The scheduling of these tasks can be easily controlled by using customized schedulers. A task must not throw an exception.

A pool is DefaultConstructible, CopyConstructible and Assignable. It has reference semantics; all copies of the same pool are equivalent and interchangeable. All operations on a pool except assignment are strongly thread safe or sequentially consistent; that is, the behavior of concurrent calls is as if the calls have been issued sequentially in an unspecified order.

Parameters:

  Task | A function object which implements the operator 'void operator() (void) const'. The operator () is called by the pool to execute the task. Exceptions are ignored.
  SchedulingPolicy | A task container which determines how tasks are scheduled. It is guaranteed that this container is accessed only by one thread at a time. The scheduler shall not throw exceptions.

Remarks:
  The pool class is thread-safe.

See also:
  Tasks: task_func, prio_task_func
  Scheduling policies: fifo_scheduler, lifo_scheduler, prio_scheduler

Definition at line 73 of file pool.hpp.

## Member Typedef Documentation

template<typename Task = task_func, template< typename > class SchedulingPolicy = fifo_scheduler, template< typename > class SizePolicy = static_size, template< typename > class SizePolicyController = resize_controller, template< typename > class ShutdownPolicy = wait_for_all_tasks>

typedef SchedulingPolicy<task_type> boost::threadpool::thread_pool< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::scheduler_type

Indicates the scheduler's type.

Definition at line 85 of file pool.hpp.

template<typename Task = task_func, template< typename > class SchedulingPolicy = fifo_scheduler, template< typename > class SizePolicy = static_size, template< typename > class SizePolicyController = resize_controller, template< typename > class ShutdownPolicy = wait_for_all_tasks>

typedef SizePolicyController<pool_core_type> boost::threadpool::thread_pool< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::size_controller_type

Definition at line 92 of file pool.hpp.

template<typename Task = task_func, template< typename > class SchedulingPolicy = fifo_scheduler, template< typename > class SizePolicy = static_size, template< typename > class SizePolicyController = resize_controller, template< typename > class ShutdownPolicy = wait_for_all_tasks>

typedef SizePolicy<pool_core_type> boost::threadpool::thread_pool< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::size_policy_type

Definition at line 91 of file pool.hpp.

template<typename Task = task_func, template< typename > class SchedulingPolicy = fifo_scheduler, template< typename > class SizePolicy = static_size, template< typename > class SizePolicyController = resize_controller, template< typename > class ShutdownPolicy = wait_for_all_tasks>

typedef Task boost::threadpool::thread_pool< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::task_type

Indicates the task's type.

Definition at line 84 of file pool.hpp.

## Constructor & Destructor Documentation

template<typename Task = task_func, template< typename > class SchedulingPolicy = fifo_scheduler, template< typename > class SizePolicy = static_size, template< typename > class SizePolicyController = resize_controller, template< typename > class ShutdownPolicy = wait_for_all_tasks>

boost::threadpool::thread_pool< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::thread_pool | ( | size_t | initial_threads = `0` | ) |

Constructor.

Parameters:

  initial_threads | The pool is immediately resized to set the specified number of threads. The pool's actual number threads depends on the SizePolicy.

Definition at line 99 of file pool.hpp.

## Member Function Documentation

template<typename Task = task_func, template< typename > class SchedulingPolicy = fifo_scheduler, template< typename > class SizePolicy = static_size, template< typename > class SizePolicyController = resize_controller, template< typename > class ShutdownPolicy = wait_for_all_tasks>

size_t boost::threadpool::thread_pool< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::active | ( |  | ) | const

Returns the number of tasks which are currently executed.

Returns:
  The number of active tasks.

Definition at line 139 of file pool.hpp.

template<typename Task = task_func, template< typename > class SchedulingPolicy = fifo_scheduler, template< typename > class SizePolicy = static_size, template< typename > class SizePolicyController = resize_controller, template< typename > class ShutdownPolicy = wait_for_all_tasks>

void boost::threadpool::thread_pool< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::clear | ( |  | ) |

Removes all pending tasks from the pool's scheduler.

Definition at line 156 of file pool.hpp.

template<typename Task = task_func, template< typename > class SchedulingPolicy = fifo_scheduler, template< typename > class SizePolicy = static_size, template< typename > class SizePolicyController = resize_controller, template< typename > class ShutdownPolicy = wait_for_all_tasks>

bool boost::threadpool::thread_pool< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::empty | ( |  | ) | const

Indicates that there are no tasks pending.

Returns:
  true if there are no tasks ready for execution.

Remarks:
  This function is more efficient that the check 'pending() == 0'.

Definition at line 166 of file pool.hpp.

template<typename Task = task_func, template< typename > class SchedulingPolicy = fifo_scheduler, template< typename > class SizePolicy = static_size, template< typename > class SizePolicyController = resize_controller, template< typename > class ShutdownPolicy = wait_for_all_tasks>

size_t boost::threadpool::thread_pool< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::pending | ( |  | ) | const

Returns the number of tasks which are ready for execution.

Returns:
  The number of pending tasks.

Definition at line 148 of file pool.hpp.

template<typename Task = task_func, template< typename > class SchedulingPolicy = fifo_scheduler, template< typename > class SizePolicy = static_size, template< typename > class SizePolicyController = resize_controller, template< typename > class ShutdownPolicy = wait_for_all_tasks>

bool boost::threadpool::thread_pool< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::schedule | ( | task_type const & | task | ) |

Schedules a task for asynchronous execution. The task will be executed once only.

Parameters:

  task | The task function object. It should not throw execeptions.

Returns:
  true, if the task could be scheduled and false otherwise.

Definition at line 130 of file pool.hpp.

template<typename Task = task_func, template< typename > class SchedulingPolicy = fifo_scheduler, template< typename > class SizePolicy = static_size, template< typename > class SizePolicyController = resize_controller, template< typename > class ShutdownPolicy = wait_for_all_tasks>

size_t boost::threadpool::thread_pool< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::size | ( |  | ) | const

Gets the number of threads in the pool.

Returns:
  The number of threads.

Definition at line 120 of file pool.hpp.

template<typename Task = task_func, template< typename > class SchedulingPolicy = fifo_scheduler, template< typename > class SizePolicy = static_size, template< typename > class SizePolicyController = resize_controller, template< typename > class ShutdownPolicy = wait_for_all_tasks>

size_controller_type boost::threadpool::thread_pool< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::size_controller | ( |  | ) |

Gets the size controller which manages the number of threads in the pool.

Returns:
  The size controller.

See also:
  SizePolicy

Definition at line 111 of file pool.hpp.

template<typename Task = task_func, template< typename > class SchedulingPolicy = fifo_scheduler, template< typename > class SizePolicy = static_size, template< typename > class SizePolicyController = resize_controller, template< typename > class ShutdownPolicy = wait_for_all_tasks>

void boost::threadpool::thread_pool< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::wait | ( | size_t | task_threshold = `0` | ) | const

The current thread of execution is blocked until the sum of all active and pending tasks is equal or less than a given threshold.

Parameters:

  task_threshold | The maximum number of tasks in pool and scheduler.

Definition at line 176 of file pool.hpp.

template<typename Task = task_func, template< typename > class SchedulingPolicy = fifo_scheduler, template< typename > class SizePolicy = static_size, template< typename > class SizePolicyController = resize_controller, template< typename > class ShutdownPolicy = wait_for_all_tasks>

bool boost::threadpool::thread_pool< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::wait | ( | xtime const & | timestamp,
|  | size_t | task_threshold = `0`
| ) |  | const

The current thread of execution is blocked until the timestamp is met or the sum of all active and pending tasks is equal or less than a given threshold.

Parameters:

  timestamp | The time when function returns at the latest.
  task_threshold | The maximum number of tasks in pool and scheduler.

Returns:
  true if the task sum is equal or less than the threshold, false otherwise.

Definition at line 189 of file pool.hpp.

Copyright © 2005-2008 Philipp Henkel | Overview | Reference | Tutorial | Examples | Design