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

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

#include <ThreadPool2.hxx>

Inheritance diagram for Utils::ThreadPool2:
Utils::ThreadPoolBase

Public Member Functions

 ThreadPool2 (unsigned nthread=std::max(unsigned(1), unsigned(std::thread::hardware_concurrency() -1)))
 Constructs a new ThreadPool1 with a specified number of threads.
 
virtual ~ThreadPool2 ()
 Destroys the ThreadPool1 and stops all worker threads.
 
void exec (FUN &&fun) override
 Executes a task in the thread pool.
 
void wait () override
 
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 ThreadPool2 class is derived from ThreadPoolBase and provides functionality to execute tasks concurrently using a pool of worker threads. Based on tghe code from https://github.com/nbsdx/ThreadPool/tree/master

Constructor & Destructor Documentation

◆ ThreadPool2()

Utils::ThreadPool2::ThreadPool2 ( 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).

◆ ~ThreadPool2()

virtual Utils::ThreadPool2::~ThreadPool2 ( )
inlinevirtual

Destroys the ThreadPool1 and stops all worker threads.

Member Function Documentation

◆ exec()

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

Executes a task in the thread pool.

Parameters
jobThe function to be executed.

Implements Utils::ThreadPoolBase.

◆ Name()

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

Returns the name of the thread pool.

◆ name()

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

Implements Utils::ThreadPoolBase.

◆ thread_count()

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

Returns the number of threads in the pool.

Returns
The number of threads.

Implements Utils::ThreadPoolBase.

◆ wait()

void Utils::ThreadPool2::wait ( )
inlineoverridevirtual

Implements Utils::ThreadPoolBase.


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