Class ThreadPool#

Class Documentation#

class ThreadPool#

ThreadPool is a multi-threading task scheduler.

Public Functions

explicit ThreadPool(u32 threads = (std::thread::hardware_concurrency() - 1))#

Constructor.

Parameters:

threads – Max amount of threads to use for tasks.

~ThreadPool()#

Destructor.

consteval ThreadPool(const ThreadPool&) = delete#

Copy constructor.

consteval ThreadPool &operator=(const ThreadPool&) = delete#

Copy assignment operator.

consteval ThreadPool(ThreadPool&&) noexcept = delete#

Move constructor.

consteval ThreadPool &operator=(ThreadPool&&) noexcept = delete#

Move assignment operator.

template<typename F, typename ...Args>
void EnqueueWork(F &&f, Args&&... args)#

Enqueue work (Call given function on separate thread).

Template Parameters:
  • F – Functor to work on.

  • Args – Parameters of the functor.

Parameters:
  • f – Functor to work on.

  • argsOptional arguments.

template<typename F, typename ...Args>
auto EnqueueTask(F &&f, Args&&... args) -> std::future<std::invoke_result_t<F, Args...>>#

Enqueue task (Call given function on seperate thread and get a future).

Template Parameters:
  • F – Functor to work on.

  • Args – Parameters of the functor.

Parameters:
  • f – Functor to work on.

  • argsOptional arguments.

Returns:

Future for the result of the given functor.