Thread pool. More...
#include <pool_core.hpp>
Public Types | |
typedef pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy > | pool_type |
Indicates the thread pool's type. | |
typedef SchedulingPolicy < task_type > | scheduler_type |
Indicates the scheduler's type. | |
typedef ShutdownPolicy< pool_type > | shutdown_policy_type |
Indicates the shutdown policy's type. | |
typedef SizePolicyController < pool_type > | size_controller_type |
typedef SizePolicy< pool_type > | size_policy_type |
Indicates the sizer's type. | |
typedef Task | task_type |
Indicates the task's type. | |
typedef worker_thread< pool_type > | worker_type |
Public Member Functions | |
size_t | active () const volatile |
BOOST_STATIC_ASSERT (function_traits< task_type()>::arity==0) | |
BOOST_STATIC_ASSERT (is_void< typename result_of< task_type()>::type >::value) | |
void | clear () volatile |
bool | empty () const volatile |
size_t | pending () const volatile |
pool_core () | |
Constructor. | |
bool | schedule (task_type const &task) volatile |
void | shutdown () |
size_t | size () const volatile |
size_controller_type | size_controller () |
void | wait (size_t const task_threshold=0) const volatile |
bool | wait (xtime const ×tamp, size_t const task_threshold=0) const volatile |
~pool_core () | |
Destructor. | |
Private Member Functions | |
bool | execute_task () volatile |
bool | resize (size_t const worker_count) volatile |
void | terminate_all_workers (bool const wait) volatile |
void | worker_destructed (shared_ptr< worker_type > worker) volatile |
void | worker_died_unexpectedly (shared_ptr< worker_type > worker) volatile |
Private Attributes | |
volatile size_t | m_active_worker_count |
recursive_mutex | m_monitor |
scheduler_type | m_scheduler |
scoped_ptr< size_policy_type > | m_size_policy |
volatile size_t | m_target_worker_count |
condition | m_task_or_terminate_workers_event |
bool | m_terminate_all_workers |
std::vector< shared_ptr < worker_type > > | m_terminated_workers |
volatile size_t | m_worker_count |
condition | m_worker_idle_or_terminated_event |
Friends | |
class | ShutdownPolicy< pool_type > |
class | SizePolicy< pool_type > |
class | worker_thread< pool_type > |
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_impl is DefaultConstructible and NonCopyable.
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. |
Scheduler | 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. |
Definition at line 75 of file pool_core.hpp.
typedef pool_core<Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy > boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::pool_type |
Indicates the thread pool's type.
Definition at line 87 of file pool_core.hpp.
typedef SchedulingPolicy<task_type> boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::scheduler_type |
Indicates the scheduler's type.
Definition at line 82 of file pool_core.hpp.
typedef ShutdownPolicy<pool_type> boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::shutdown_policy_type |
Indicates the shutdown policy's type.
Definition at line 94 of file pool_core.hpp.
typedef SizePolicyController<pool_type> boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::size_controller_type |
Definition at line 91 of file pool_core.hpp.
typedef SizePolicy<pool_type> boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::size_policy_type |
Indicates the sizer's type.
Definition at line 88 of file pool_core.hpp.
typedef Task boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::task_type |
Indicates the task's type.
Definition at line 81 of file pool_core.hpp.
typedef worker_thread<pool_type> boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::worker_type |
Definition at line 96 of file pool_core.hpp.
boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::pool_core | ( | ) | [inline] |
Constructor.
Definition at line 137 of file pool_core.hpp.
boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::~pool_core | ( | ) | [inline] |
Destructor.
Definition at line 151 of file pool_core.hpp.
size_t boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::active | ( | ) | const volatile [inline] |
Returns the number of tasks which are currently executed.
Definition at line 201 of file pool_core.hpp.
boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::BOOST_STATIC_ASSERT | ( | function_traits< task_type()>::arity | = =0 | ) |
boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::BOOST_STATIC_ASSERT | ( | is_void< typename result_of< task_type()>::type >::value | ) |
void boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::clear | ( | ) | volatile [inline] |
Removes all pending tasks from the pool's scheduler.
Definition at line 219 of file pool_core.hpp.
bool boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::empty | ( | ) | const volatile [inline] |
Indicates that there are no tasks pending.
Definition at line 230 of file pool_core.hpp.
bool boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::execute_task | ( | ) | volatile [inline, private] |
Definition at line 401 of file pool_core.hpp.
size_t boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::pending | ( | ) | const volatile [inline] |
Returns the number of tasks which are ready for execution.
Definition at line 210 of file pool_core.hpp.
bool boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::resize | ( | size_t const | worker_count | ) | volatile [inline, private] |
Changes the number of worker threads in the pool. The resizing is handled by the SizePolicy.
threads | The new number of worker threads. |
Definition at line 329 of file pool_core.hpp.
bool boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::schedule | ( | task_type const & | task | ) | volatile [inline] |
Schedules a task for asynchronous execution. The task will be executed once only.
task | The task function object. It should not throw execeptions. |
Definition at line 182 of file pool_core.hpp.
void boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::shutdown | ( | ) | [inline] |
Definition at line 173 of file pool_core.hpp.
size_t boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::size | ( | ) | const volatile [inline] |
Gets the number of threads in the pool.
Definition at line 167 of file pool_core.hpp.
size_controller_type boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::size_controller | ( | ) | [inline] |
Gets the size controller which manages the number of threads in the pool.
Definition at line 159 of file pool_core.hpp.
void boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::terminate_all_workers | ( | bool const | wait | ) | volatile [inline, private] |
Definition at line 296 of file pool_core.hpp.
void boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::wait | ( | size_t const | task_threshold = 0 | ) | const volatile [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.
task_threshold | The maximum number of tasks in pool and scheduler. |
Definition at line 241 of file pool_core.hpp.
bool boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::wait | ( | xtime const & | timestamp, |
size_t const | task_threshold = 0 |
||
) | const volatile [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.
timestamp | The time when function returns at the latest. |
task_threshold | The maximum number of tasks in pool and scheduler. |
Definition at line 269 of file pool_core.hpp.
void boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::worker_destructed | ( | shared_ptr< worker_type > | worker | ) | volatile [inline, private] |
Definition at line 387 of file pool_core.hpp.
void boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::worker_died_unexpectedly | ( | shared_ptr< worker_type > | worker | ) | volatile [inline, private] |
Definition at line 369 of file pool_core.hpp.
friend class ShutdownPolicy< pool_type > [friend] |
Definition at line 113 of file pool_core.hpp.
friend class SizePolicy< pool_type > [friend] |
Definition at line 112 of file pool_core.hpp.
friend class worker_thread< pool_type > [friend] |
Definition at line 106 of file pool_core.hpp.
volatile size_t boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::m_active_worker_count [private] |
Definition at line 119 of file pool_core.hpp.
recursive_mutex boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::m_monitor [mutable, private] |
Definition at line 131 of file pool_core.hpp.
scheduler_type boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::m_scheduler [private] |
Definition at line 124 of file pool_core.hpp.
scoped_ptr<size_policy_type> boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::m_size_policy [private] |
Definition at line 125 of file pool_core.hpp.
volatile size_t boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::m_target_worker_count [private] |
Definition at line 118 of file pool_core.hpp.
condition boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::m_task_or_terminate_workers_event [mutable, private] |
Definition at line 133 of file pool_core.hpp.
bool boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::m_terminate_all_workers [private] |
Definition at line 127 of file pool_core.hpp.
std::vector<shared_ptr<worker_type> > boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::m_terminated_workers [private] |
Definition at line 128 of file pool_core.hpp.
volatile size_t boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::m_worker_count [private] |
Definition at line 117 of file pool_core.hpp.
condition boost::threadpool::detail::pool_core< Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy >::m_worker_idle_or_terminated_event [mutable, private] |
Definition at line 132 of file pool_core.hpp.