Class ThreadPool

Class Documentation

class ThreadPool

Thread pool singleton.

Public Functions

template<typename F, typename ...Args, typename R = std::invoke_result_t<F&&, Args&&...>>
inline std::shared_future<R> Exec(F func, Args... args)

Place a task into the queue with an expected return value.

Parameters:
  • func – The task to execute

  • args – The arguments to the task function

Throws:

BadInitStateException – If the pool is not running

Returns:

A future that will be fulfilled when the task completes

template<typename F, typename ...Args>
inline std::stop_source ExecContinuous(F func, Args... args)

Run a looping function on the thread pool that can be signaled to stop.

Note

All functions will be automatically signaled to stop when the pool is

Parameters:
  • func – The function to execute

  • args – The arguments to the task function

Throws:

BadInitStateException – If the pool is not running

Returns:

An object by which the function can be requested to stop

void Start()

Start the thread pool.

Throws:

BadInitStateException – If the pool is running

void Stop()

Signal all continuous functions to stop and stop the pool.

Throws:

BadInitStateException – If the pool is not running

bool IsRunning() const

Check if the pool is running.

Returns:

Whether the pool is running

std::size_t GetThreadCount() const

Check how many threads are in the pool.

Throws:

BadInitStateException – If the pool is not running

Returns:

Number of threads in pool

Public Static Functions

static ThreadPool &Get()

Get the instance and create one if there isn’t one.

Returns:

The instance