openGPMP
Open Source Mathematics Package
Public Member Functions | List of all members
gpmp::core::ThreadDispatch Class Reference

A class that provides a function to dispatch a function call to a thread pool and return a future object for obtaining the result. More...

#include <threads.hpp>

Public Member Functions

template<typename Function , typename... Args>
auto dispatch (ThreadPool &pool, Function &&func, Args &&...args) -> std::future< typename std::invoke_result< Function, Args... >::type >
 Dispatches a function call to a ThreadPool and returns a future object for obtaining the result. More...
 

Detailed Description

A class that provides a function to dispatch a function call to a thread pool and return a future object for obtaining the result.

Examples
factors.cpp, and primes.cpp.

Definition at line 204 of file threads.hpp.

Member Function Documentation

◆ dispatch()

template<typename Function , typename... Args>
auto gpmp::core::ThreadDispatch::dispatch ( ThreadPool pool,
Function &&  func,
Args &&...  args 
) -> std::future<typename std::invoke_result<Function, Args...>::type>
inline

Dispatches a function call to a ThreadPool and returns a future object for obtaining the result.

Template Parameters
FunctionThe type of the function to be dispatched.
ArgsThe types of the arguments to be passed to the function.
Parameters
poolThe ThreadPool object to which the function call is dispatched.
funcThe function to be dispatched.
argsThe arguments to be passed to the function.
Returns
A future object for obtaining the result of the dispatched function call.

Definition at line 220 of file threads.hpp.

222  {
223 
224  // enqueue the function call to the thread pool
225  auto result = pool.enqueue(std::forward<Function>(func),
226  std::forward<Args>(args)...);
227 
228  // return the future object to get the result later
229  return result;
230  }

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