class ssts::task_pool

Task Pool that can run any callable object.

This class is general purpose thread pool that can launch task asyncronously. It is possible to get an asyncronous result of a task execution.

Public Functions

inline explicit task_pool(const unsigned int num_threads = std::thread::hardware_concurrency())


Creates a

ssts::task_pool instance with the given number of threads.
  • num_threads: Number of threads that will be used in the underlying ssts::task_pool.

inline ~task_pool()


Destructs this after all joinable threads are terminated.

inline void stop()

Stop all threads.

Stop thread pool and join all joinable threads.

template<typename FunctionType>
inline auto run(FunctionType &&f, const std::optional<size_t> &task_hash = std::nullopt)

Run a callable object asynchronously.

Enqueue a new task with the given callable object. The enqueued task will run as soon as a thread is available. Returns the result of the asynchronous computation.


std::future task result

Template Parameters
  • FunctionType: Types of the callable object.

  • f: Callable object.