Pool Control¶
Pool size¶
You can control the threadpool size when instantiating it with the constructors. Here are the different constructors you can use:
-
ThreadPool::ThreadPool
::
ThreadPool
(std::size_t pool_size)¶ Constructs a ThreadPool.
- Parameters
pool_size
: Number of threads to start.
Constructs a ThreadPool.
- Parameters
pool_size
: Number of threads to start.hooks
: Hooks to register in the pool.
The pool_size
parameter will determine the number of workers(threads)
the pool will start when instantiating.
Stopping the pool¶
You can stop the pool with:
-
void
ThreadPool::ThreadPool
::
stop
() Stop the ThreadPool.
A stopped ThreadPool will discard any task dispatched to it. All workers will discard new tasks, but the threads will not exit.
You can check if the pool is stopped with:
-
bool
ThreadPool::ThreadPool
::
is_stopped
() const Check the state of the threadpool.
- Return
- True if the ThreadPool is stopped, false otherwise.
Checking the pool¶
You can check the current state of the workers with:
-
std::size_t
ThreadPool::ThreadPool
::
threads_available
() const Check on the number of threads not currently working.
The number might be imprecise, as between the time the value is read and returned, a thread might become unavailable.
- Return
- The number of threads currently waiting for a task.
-
std::size_t
ThreadPool::ThreadPool
::
threads_working
() const Check on the number of threads currently working.
The number might be imprecise, as between the time the value is read and returned, a thread might finish a task and become available.
- Return
- The number of threads currently working.