libDwm-0.9.45
Dwm::ThreadPool< N, F, Args > Class Template Reference

Encapsulate a trivial thread pool. More...

#include <DwmThreadPool.hh>

Public Member Functions

 ThreadPool ()
 Constructs the thread pool and starts the threads.
 
bool Start ()
 Starts the threads.
 
void AddTask (F fn, Args ...args)
 Adds a task to be executed by the thread pool.
 
void Stop ()
 Stops the threads.
 
void ClearTasks ()
 Clears all the tasks from the task queue.
 
 ~ThreadPool ()
 Destructor.
 

Detailed Description

template<size_t N, typename F, typename... Args>
requires (std::invocable<F,Args...> && std::is_copy_assignable_v<F> && (std::is_copy_assignable_v<Args> && ...))
class Dwm::ThreadPool< N, F, Args >

Encapsulate a trivial thread pool.

N is the number of threads and F is a functor type that takes Args when invoked.

Work is added to the pool via AddTask().

Member Function Documentation

◆ AddTask()

template<size_t N, typename F , typename... Args>
void Dwm::ThreadPool< N, F, Args >::AddTask ( F fn,
Args ... args )
inline

Adds a task to be executed by the thread pool.

fn is a function object and args are the arguments to the function.

◆ ClearTasks()

template<size_t N, typename F , typename... Args>
void Dwm::ThreadPool< N, F, Args >::ClearTasks ( )
inline

Clears all the tasks from the task queue.

May be useful if you want to Stop() without waiting for queued tasks to complete.

◆ Start()

template<size_t N, typename F , typename... Args>
bool Dwm::ThreadPool< N, F, Args >::Start ( )
inline

Starts the threads.

Returns true on success, false on failure. A failure indicates that the threads had not been joined (i.e. Stop() had not been called).

◆ Stop()

template<size_t N, typename F , typename... Args>
void Dwm::ThreadPool< N, F, Args >::Stop ( )
inline

Stops the threads.

Note that we will wait for all remaining tasks to be completed.


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