Threadpool
Loading...
Searching...
No Matches
maxtek::threadpool Class Reference

#include <threadpool.hpp>

Public Member Functions

 threadpool (size_t threads=std::thread::hardware_concurrency())
 constructs a new threadpool
 
 ~threadpool ()
 destroys threadpool after calling shutdown if necessary
 
template<class F , class... Args>
std::future< std::result_of_t< F(Args...)> > submit (F &&function, Args &&...args)
 submits a function with its arguments to the threadpool
 
bool active () const
 check if the threadpool is active
 
void shutdown ()
 shut down threadpool by joining threads and rejecting submissions
 

Constructor & Destructor Documentation

◆ threadpool()

maxtek::threadpool::threadpool ( size_t threads = std::thread::hardware_concurrency())

constructs a new threadpool

Parameters
threadsnumber of threads to use for constructing the threadpool
Exceptions
std::runtime_errorif threads is set to zero

◆ ~threadpool()

maxtek::threadpool::~threadpool ( )

destroys threadpool after calling shutdown if necessary

Member Function Documentation

◆ active()

bool maxtek::threadpool::active ( ) const

check if the threadpool is active

Returns
true if the threadpool is active, false if it has been shut down

◆ shutdown()

void maxtek::threadpool::shutdown ( )

shut down threadpool by joining threads and rejecting submissions

Exceptions
std::runtime_errorif the thread pool has already been shut down

◆ submit()

template<class F , class... Args>
std::future< std::result_of_t< F(Args...)> > maxtek::threadpool::submit ( F && function,
Args &&... args )
inline

submits a function with its arguments to the threadpool

Template Parameters
Ffunction signature
Argsfunction argument types
Parameters
functionfunction signature
argsarguments to pass to the function
Returns
a future holding the asynchronous function result
Exceptions
std::runtime_errorif the thread pool has been shut down

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