cpp-mate  0.7
Helpful library for C++.
CppMate::ThreadPool< R > Class Template Referencefinal

Represents thread pool. More...

#include <ThreadPool.hpp>

Classes

class  State
 

Public Member Functions

 ThreadPool (unsigned maxThreads=0)
 Constructor. More...
 
 ThreadPool (const ThreadPool &other)=delete
 
 ThreadPool (ThreadPool &&other)=default
 
ThreadPooloperator= (const ThreadPool &other)=delete
 
ThreadPooloperator= (ThreadPool &&other)=default
 
 ~ThreadPool ()
 
unsigned getMaxThreads () const
 Returns the maximum possible number of threads in the pool. More...
 
unsigned getWorkersCount () const
 Returns the number of active workers in the pool at the moment. More...
 
unsigned getPendingTasksCount () const
 Returns number of pending tasks at the moment. More...
 
bool hasPendingTasks () const
 Indicates that pool has at least one pending task at the moment. More...
 
unsigned getWaitingCount () const
 Returns the number of workers is waiting for a job. More...
 
template<typename F , typename... A>
std::future< R > addTask (F &&task, A &&... args)
 Adds a new task for execution. More...
 

Detailed Description

template<typename R = int>
class CppMate::ThreadPool< R >

Represents thread pool.

Constructor & Destructor Documentation

◆ ThreadPool() [1/3]

template<typename R = int>
CppMate::ThreadPool< R >::ThreadPool ( unsigned  maxThreads = 0)
inlineexplicit

Constructor.

Parameters
maxThreadsthe desired value of maximum possible threads in the pool. Zero value means choosing an optimal value for the current platform.

◆ ThreadPool() [2/3]

template<typename R = int>
CppMate::ThreadPool< R >::ThreadPool ( const ThreadPool< R > &  other)
delete

◆ ThreadPool() [3/3]

template<typename R = int>
CppMate::ThreadPool< R >::ThreadPool ( ThreadPool< R > &&  other)
default

◆ ~ThreadPool()

template<typename R = int>
CppMate::ThreadPool< R >::~ThreadPool ( )
inline

Destructor.

Member Function Documentation

◆ addTask()

template<typename R = int>
template<typename F , typename... A>
std::future<R> CppMate::ThreadPool< R >::addTask ( F &&  task,
A &&...  args 
)
inline

Adds a new task for execution.

Parameters
taskthe task to add.
argsthe task arguments.
Returns
future object to tracking task results.
Exceptions
std::system_error

◆ getMaxThreads()

template<typename R = int>
unsigned CppMate::ThreadPool< R >::getMaxThreads ( ) const
inline

Returns the maximum possible number of threads in the pool.

Returns
maximum possible number of threads in the pool.

◆ getPendingTasksCount()

template<typename R = int>
unsigned CppMate::ThreadPool< R >::getPendingTasksCount ( ) const
inline

Returns number of pending tasks at the moment.

Returns
number of pending tasks at the moment.

◆ getWaitingCount()

template<typename R = int>
unsigned CppMate::ThreadPool< R >::getWaitingCount ( ) const
inline

Returns the number of workers is waiting for a job.

Returns
number of workers is waiting for a job.

◆ getWorkersCount()

template<typename R = int>
unsigned CppMate::ThreadPool< R >::getWorkersCount ( ) const
inline

Returns the number of active workers in the pool at the moment.

Returns
number of active workers in the pool at the moment.

◆ hasPendingTasks()

template<typename R = int>
bool CppMate::ThreadPool< R >::hasPendingTasks ( ) const
inline

Indicates that pool has at least one pending task at the moment.

Returns
true if pool has pending task(s); false otherwise.

◆ operator=() [1/2]

template<typename R = int>
ThreadPool& CppMate::ThreadPool< R >::operator= ( const ThreadPool< R > &  other)
delete

◆ operator=() [2/2]

template<typename R = int>
ThreadPool& CppMate::ThreadPool< R >::operator= ( ThreadPool< R > &&  other)
default

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