|
| 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 ×tamp, 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...
|
|
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. |
- See also
- Tasks: task_func, prio_task_func
-
Scheduling policies: fifo_scheduler, lifo_scheduler, prio_scheduler
Definition at line 73 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>
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>
Indicates the task's type.
Definition at line 84 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>
Returns the number of tasks which are currently executed.
- Returns
- The number of active tasks.
Definition at line 139 of file pool.hpp.
shared_ptr< pool_core_type > m_core
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>
Removes all pending tasks from the pool's scheduler.
Definition at line 156 of file pool.hpp.
shared_ptr< pool_core_type > m_core
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>
Indicates that there are no tasks pending.
- Returns
- true if there are no tasks ready for execution.
Definition at line 166 of file pool.hpp.
shared_ptr< pool_core_type > m_core
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>
Returns the number of tasks which are ready for execution.
- Returns
- The number of pending tasks.
Definition at line 148 of file pool.hpp.
shared_ptr< pool_core_type > m_core
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>
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.
132 return m_core->schedule(task);
shared_ptr< pool_core_type > m_core
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>
Gets the number of threads in the pool.
- Returns
- The number of threads.
Definition at line 120 of file pool.hpp.
shared_ptr< pool_core_type > m_core
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>
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.
113 return m_core->size_controller();
shared_ptr< pool_core_type > m_core
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.
178 m_core->wait(task_threshold);
shared_ptr< pool_core_type > m_core
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.
191 return m_core->wait(timestamp, task_threshold);
shared_ptr< pool_core_type > m_core