ctrl-utils
Public Member Functions | List of all members
ctrl_utils::ThreadPool< T > Class Template Reference

Public Member Functions

 ThreadPool (size_t num_threads)
 
virtual ~ThreadPool ()
 
std::future< T > Submit (std::function< T()> &&job)
 
std::future< T > Submit (std::function< T()> &job)
 
void Terminate ()
 

Constructor & Destructor Documentation

◆ ThreadPool()

template<typename T >
ctrl_utils::ThreadPool< T >::ThreadPool ( size_t  num_threads)
inline

Constructs a thread pool with the specified number of threads.

Parameters
num_threadsNumber of threads to spawn. If zero, spawns the maximum number of concurrent threads supported by the hardware.

◆ ~ThreadPool()

template<typename T >
virtual ctrl_utils::ThreadPool< T >::~ThreadPool ( )
inlinevirtual

Terminates the thread pool and joins the threads.

Member Function Documentation

◆ Submit()

template<typename T >
std::future<T> ctrl_utils::ThreadPool< T >::Submit ( std::function< T()> &&  job)
inline

Submits a job to the thread pool.

Parameters
jobJob to submit.
Returns
Future value returned by the job.

◆ Terminate()

template<typename T >
void ctrl_utils::ThreadPool< T >::Terminate ( )
inline

Terminates the thread pool.

Jobs that have not yet been initiated will return a future exception.


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