![]() |
UtilsLite
Utilities for C++ programming
|
A thread pool for concurrent task execution with worker management. More...
#include <ThreadPool3.hxx>
Public Member Functions | |
ThreadPool3 (unsigned nthread=std::max(unsigned(1), unsigned(std::thread::hardware_concurrency() -1))) | |
Constructs a new ThreadPool5 instance with a specified number of threads. | |
virtual | ~ThreadPool3 () |
Destructor for the ThreadPool5 class. | |
void | exec (FUN &&fun) override |
Executes a task and assigns it to an available worker. | |
void | wait () override |
Waits for all tasks to be completed. | |
unsigned | thread_count () const override |
Gets the current number of threads in the pool. | |
char const * | name () const override |
![]() | |
ThreadPoolBase (ThreadPoolBase const &)=delete | |
ThreadPoolBase (ThreadPoolBase &&)=delete | |
ThreadPoolBase & | operator= (ThreadPoolBase const &)=delete |
ThreadPoolBase & | operator= (ThreadPoolBase &&)=delete |
ThreadPoolBase ()=default | |
template<typename Func, typename... Args> | |
void | run (Func &&func, Args &&... args) |
Static Public Member Functions | |
static char const * | Name () |
Gets the name of the thread pool implementation. | |
Additional Inherited Members | |
![]() | |
typedef std::function< void(void)> | FUN |
A thread pool for concurrent task execution with worker management.
The ThreadPool3
class provides an implementation of a thread pool that allows for efficient concurrent execution of tasks. This class manages a collection of worker threads that can be dynamically resized, and utilizes a semaphore-based mechanism for worker synchronization.
This class extends ThreadPoolBase
and supports task execution, joining, and resizing of worker threads.
|
inline |
Constructs a new ThreadPool5 instance with a specified number of threads.
nthread | The number of threads to create in the pool. Defaults to the maximum hardware threads available. |
|
inlinevirtual |
Destructor for the ThreadPool5 class.
Ensures all workers are stopped and joined before destruction.
|
inlineoverridevirtual |
Executes a task and assigns it to an available worker.
fun | The function to be executed as a task. |
Implements Utils::ThreadPoolBase.
|
inlinestatic |
Gets the name of the thread pool implementation.
|
inlineoverridevirtual |
Implements Utils::ThreadPoolBase.
|
inlineoverridevirtual |
Gets the current number of threads in the pool.
Implements Utils::ThreadPoolBase.
|
inlineoverridevirtual |
Waits for all tasks to be completed.
Implements Utils::ThreadPoolBase.