thread-pool
Loading...
Searching...
No Matches
dp::thread_pool< FunctionType, ThreadType > Class Template Reference

#include <thread_pool.h>

Public Member Functions

 thread_pool (const unsigned int &number_of_threads=std::thread::hardware_concurrency())
 
 ~thread_pool ()
 
 thread_pool (const thread_pool &)=delete
 thread pool is non-copyable
 
thread_pooloperator= (const thread_pool &)=delete
 
template<typename Function , typename... Args, typename ReturnType = std::invoke_result_t<Function &&, Args &&...>>
requires std::invocable<Function, Args...>
std::future< ReturnType > enqueue (Function f, Args... args)
 Enqueue a task into the thread pool that returns a result.
 
template<typename Function , typename... Args>
requires std::invocable<Function, Args...> && std::is_same_v<void, std::invoke_result_t<Function &&, Args &&...>>
void enqueue_detach (Function &&func, Args &&...args)
 Enqueue a task to be executed in the thread pool that returns void.
 
auto size () const
 

Detailed Description

template<typename FunctionType = details::default_function_type, typename ThreadType = std::jthread>
requires std::invocable<FunctionType> && std::is_same_v<void, std::invoke_result_t<FunctionType>>
class dp::thread_pool< FunctionType, ThreadType >
Examples
mandelbrot/source/main.cpp.

Constructor & Destructor Documentation

◆ thread_pool() [1/2]

template<typename FunctionType = details::default_function_type, typename ThreadType = std::jthread>
dp::thread_pool< FunctionType, ThreadType >::thread_pool ( const unsigned int &  number_of_threads = std::thread::hardware_concurrency())
inlineexplicit

◆ ~thread_pool()

template<typename FunctionType = details::default_function_type, typename ThreadType = std::jthread>
dp::thread_pool< FunctionType, ThreadType >::~thread_pool ( )
inline

◆ thread_pool() [2/2]

template<typename FunctionType = details::default_function_type, typename ThreadType = std::jthread>
dp::thread_pool< FunctionType, ThreadType >::thread_pool ( const thread_pool< FunctionType, ThreadType > &  )
delete

thread pool is non-copyable

Member Function Documentation

◆ enqueue()

template<typename FunctionType = details::default_function_type, typename ThreadType = std::jthread>
template<typename Function , typename... Args, typename ReturnType = std::invoke_result_t<Function &&, Args &&...>>
requires std::invocable<Function, Args...>
std::future< ReturnType > dp::thread_pool< FunctionType, ThreadType >::enqueue ( Function  f,
Args...  args 
)
inline

Enqueue a task into the thread pool that returns a result.

Note that task execution begins once the task is enqueued.

Template Parameters
FunctionAn invokable type.
ArgsArgument parameter pack
ReturnTypeThe return type of the Function
Parameters
fThe callable function
argsThe parameters that will be passed (copied) to the function.
Returns
A std::future<ReturnType> that can be used to retrieve the returned value.
Examples
mandelbrot/source/main.cpp.

◆ enqueue_detach()

template<typename FunctionType = details::default_function_type, typename ThreadType = std::jthread>
template<typename Function , typename... Args>
requires std::invocable<Function, Args...> && std::is_same_v<void, std::invoke_result_t<Function &&, Args &&...>>
void dp::thread_pool< FunctionType, ThreadType >::enqueue_detach ( Function &&  func,
Args &&...  args 
)
inline

Enqueue a task to be executed in the thread pool that returns void.

Template Parameters
FunctionAn invokable type.
ArgsArgument parameter pack for Function
Parameters
funcThe callable to be executed
argsArguments that will be passed to the function.

◆ operator=()

template<typename FunctionType = details::default_function_type, typename ThreadType = std::jthread>
thread_pool & dp::thread_pool< FunctionType, ThreadType >::operator= ( const thread_pool< FunctionType, ThreadType > &  )
delete

◆ size()

template<typename FunctionType = details::default_function_type, typename ThreadType = std::jthread>
auto dp::thread_pool< FunctionType, ThreadType >::size ( ) const
inline

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