UtilsLite
Utilities for C++ programming
Loading...
Searching...
No Matches
Utils::ThreadPool5 Class Reference

A thread pool for concurrent task execution with worker management. More...

#include <ThreadPool5.hxx>

Inheritance diagram for Utils::ThreadPool5:
Utils::ThreadPoolBase

Public Member Functions

 ThreadPool5 (unsigned nthread=std::max(unsigned(1), unsigned(std::thread::hardware_concurrency() -1)))
 Constructs a new ThreadPool5 instance with a specified number of threads.
 
virtual ~ThreadPool5 ()
 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
 
- Public Member Functions inherited from Utils::ThreadPoolBase
 ThreadPoolBase (ThreadPoolBase const &)=delete
 
 ThreadPoolBase (ThreadPoolBase &&)=delete
 
ThreadPoolBaseoperator= (ThreadPoolBase const &)=delete
 
ThreadPoolBaseoperator= (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

- Protected Types inherited from Utils::ThreadPoolBase
typedef std::function< void(void)> FUN
 

Detailed Description

A thread pool for concurrent task execution with worker management.

The ThreadPool5 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.

Constructor & Destructor Documentation

◆ ThreadPool5()

Utils::ThreadPool5::ThreadPool5 ( unsigned nthread = std::max(        unsigned(1),        unsigned(std::thread::hardware_concurrency()-1)      ))
inline

Constructs a new ThreadPool5 instance with a specified number of threads.

Parameters
nthreadThe number of threads to create in the pool. Defaults to the maximum hardware threads available.

◆ ~ThreadPool5()

virtual Utils::ThreadPool5::~ThreadPool5 ( )
inlinevirtual

Destructor for the ThreadPool5 class.

Ensures all workers are stopped and joined before destruction.

Member Function Documentation

◆ exec()

void Utils::ThreadPool5::exec ( FUN && fun)
inlineoverridevirtual

Executes a task and assigns it to an available worker.

Parameters
funThe function to be executed as a task.

Implements Utils::ThreadPoolBase.

◆ Name()

static char const * Utils::ThreadPool5::Name ( )
inlinestatic

Gets the name of the thread pool implementation.

Returns
A constant character pointer to the name of the thread pool.

◆ name()

char const * Utils::ThreadPool5::name ( ) const
inlineoverridevirtual

Implements Utils::ThreadPoolBase.

◆ thread_count()

unsigned Utils::ThreadPool5::thread_count ( ) const
inlineoverridevirtual

Gets the current number of threads in the pool.

Returns
The number of threads in the pool.

Implements Utils::ThreadPoolBase.

◆ wait()

void Utils::ThreadPool5::wait ( )
inlineoverridevirtual

Waits for all tasks to be completed.

Implements Utils::ThreadPoolBase.


The documentation for this class was generated from the following file: