| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Private Types | Private Attributes | List of all members
boost::threadpool::thread_pool< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy > Class Template Reference

Thread pool. More...

`#include <src/threadpool/boost/threadpool/pool.hpp>`

## Public Types
typedef Task | task_type
| Indicates the task's type. More...
typedef SchedulingPolicy< task_type > | scheduler_type
| Indicates the scheduler's type. More...
typedef SizePolicy< pool_core_type > | size_policy_type
typedef SizePolicyController< pool_core_type > | size_controller_type

## Public Member Functions
| thread_pool (size_t initial_threads=0)
| Constructor. More...
size_controller_type | size_controller ()
| Gets the size controller which manages the number of threads in the pool. More...
size_t | size () const
| Gets the number of threads in the pool. More...
bool | schedule (task_type const &task)
| Schedules a task for asynchronous execution. More...
size_t | active () const
| Returns the number of tasks which are currently executed. More...
size_t | pending () const
| Returns the number of tasks which are ready for execution. More...
void | clear ()
| Removes all pending tasks from the pool's scheduler. More...
bool | empty () const
| Indicates that there are no tasks pending. More...
void | 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. More...
bool | 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. More...

## Private Types
typedef detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy > | pool_core_type

## Private Attributes
shared_ptr< pool_core_type > | m_core
shared_ptr< void > | m_shutdown_controller

## 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 detail::pool_core<Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy> boost::threadpool::thread_pool< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::pool_core_type
| private

Definition at line 79 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 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` | ) |
| inline

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.

100 : m_core(new pool_core_type)
101 , m_shutdown_controller(static_cast<void*>(0), bind(&pool_core_type::shutdown, m_core))
102 {
103 size_policy_type::init(*m_core, initial_threads);
104 }
boost::threadpool::thread_pool::pool_core_type
detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy > pool_core_type
Definition: pool.hpp:79
boost::threadpool::thread_pool::m_shutdown_controller
shared_ptr< void > m_shutdown_controller
Definition: pool.hpp:81
std::bind
T bind(T...args)
boost::threadpool::thread_pool::m_core
shared_ptr< pool_core_type > m_core
Definition: pool.hpp:80
boost::threadpool::detail::pool_core::shutdown
void shutdown()
Definition: pool_core.hpp:173

## 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
| inline

Returns the number of tasks which are currently executed.

Returns
  The number of active tasks.

Definition at line 139 of file pool.hpp.

140 {
141 return m_core->active();
142 }
boost::threadpool::thread_pool::m_core
shared_ptr< pool_core_type > m_core
Definition: pool.hpp:80
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 | ( |  | ) |
| inline

Removes all pending tasks from the pool's scheduler.

Definition at line 156 of file pool.hpp.

157 {
158 m_core->clear();
159 }
boost::threadpool::thread_pool::m_core
shared_ptr< pool_core_type > m_core
Definition: pool.hpp:80
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
| inline

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.

167 {
168 return m_core->empty();
169 }
boost::threadpool::thread_pool::m_core
shared_ptr< pool_core_type > m_core
Definition: pool.hpp:80
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
| inline

Returns the number of tasks which are ready for execution.

Returns
  The number of pending tasks.

Definition at line 148 of file pool.hpp.

149 {
150 return m_core->pending();
151 }
boost::threadpool::thread_pool::m_core
shared_ptr< pool_core_type > m_core
Definition: pool.hpp:80
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 | ) |
| inline

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.

131 {
132 return m_core->schedule(task);
133 }
boost::threadpool::thread_pool::m_core
shared_ptr< pool_core_type > m_core
Definition: pool.hpp:80
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
| inline

Gets the number of threads in the pool.

Returns
  The number of threads.

Definition at line 120 of file pool.hpp.

121 {
122 return m_core->size();
123 }
boost::threadpool::thread_pool::m_core
shared_ptr< pool_core_type > m_core
Definition: pool.hpp:80
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 | ( |  | ) |
| inline

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.

112 {
113 return m_core->size_controller();
114 }
boost::threadpool::thread_pool::m_core
shared_ptr< pool_core_type > m_core
Definition: pool.hpp:80
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
| inline

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.

177 {
178 m_core->wait(task_threshold);
179 }
boost::threadpool::thread_pool::m_core
shared_ptr< pool_core_type > m_core
Definition: pool.hpp:80
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
| inline

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.

190 {
191 return m_core->wait(timestamp, task_threshold);
192 }
boost::threadpool::thread_pool::m_core
shared_ptr< pool_core_type > m_core
Definition: pool.hpp:80

## Member Data 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>

shared_ptr<pool_core_type> boost::threadpool::thread_pool< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::m_core
| private

Definition at line 80 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>

shared_ptr<void> boost::threadpool::thread_pool< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::m_shutdown_controller
| private

Definition at line 81 of file pool.hpp.

The documentation for this class was generated from the following file:

- GaudiMTTools/src/threadpool/boost/threadpool/pool.hpp