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

Manages a pool of worker threads for concurrent task execution. More...

#include <ThreadPool1.hxx>

Inheritance diagram for Utils::ThreadPool1:
Utils::ThreadPoolBase

Public Member Functions

 ThreadPool1 (unsigned nthread=std::max(unsigned(1), unsigned(std::thread::hardware_concurrency() -1)))
 Constructs a new ThreadPool1 with a specified number of threads.
 
virtual ~ThreadPool1 ()
 Destroys the ThreadPool1 and stops all worker threads.
 
void exec (FUN &&fun) override
 Executes a task in the thread pool.
 
void wait () override
 Waits for all tasks to finish.
 
unsigned thread_count () const override
 Returns the 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 ()
 Returns the name of the thread pool.
 

Additional Inherited Members

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

Detailed Description

Manages a pool of worker threads for concurrent task execution.

The ThreadPool1 class is derived from ThreadPoolBase and provides functionality to execute tasks concurrently using a pool of worker threads.

Constructor & Destructor Documentation

◆ ThreadPool1()

Utils::ThreadPool1::ThreadPool1 ( unsigned nthread = std::max(        unsigned(1),        unsigned(std::thread::hardware_concurrency()-1)      ))
inlineexplicit

Constructs a new ThreadPool1 with a specified number of threads.

Parameters
nthreadNumber of threads to create (default: hardware concurrency - 1).

◆ ~ThreadPool1()

virtual Utils::ThreadPool1::~ThreadPool1 ( )
inlinevirtual

Destroys the ThreadPool1 and stops all worker threads.

Member Function Documentation

◆ exec()

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

Executes a task in the thread pool.

Parameters
funThe function to be executed.

Implements Utils::ThreadPoolBase.

◆ Name()

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

Returns the name of the thread pool.

◆ name()

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

Implements Utils::ThreadPoolBase.

◆ thread_count()

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

Returns the number of threads in the pool.

Returns
The number of threads.

Implements Utils::ThreadPoolBase.

◆ wait()

void Utils::ThreadPool1::wait ( )
inlineoverridevirtual

Waits for all tasks to finish.

Implements Utils::ThreadPoolBase.


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