~CThreadPool
~CThreadPool();
System & concurrency
A queue-driven thread pool and the FIFO `CPool` convenience alias.
#include <mc/pool.h>Start the pool before relying on queued work. Stop it from a thread outside the pool; worker callbacks must handle their own exceptions.
CPool is CFIFOPool<std::function<void(void)>>. CFIFOPool inherits the lifecycle methods of CThreadPool.
template<class Queue> requires requires(Queue q, typename Queue::Item i){ {q.pop(i)} -> std::same_as<bool>; i(); } class CThreadPoolusing Item = typename Queue::Item;
~CThreadPool();
void start(size_t threadCount);
Starts workers that remove callable items from the queue. Start only once for a FIFO pool; stopping permanently disables its queue.
void stop();
Disables the queue and joins workers. For the FIFO pool, queued work is not drained; wait for required tasks before stopping. The disabled FIFO pool is not restartable.
size_t numThreads() const;
Returns the number of workers started and not yet joined by stop(). It does not count pending tasks.
template<class I> class CFIFOPool : public CThreadPool<CLQueue<I>>using Item = I;
template<class T> void push(T&& item);
Queues a callable for a worker. Start the pool before expecting execution and catch task failures inside the callable; escaping exceptions are not collected in a future.
template<class T> CFIFOPool& operator<<(T&& item);
Queues a callable through push() and returns the pool for chaining.