NAGASH 0.9.8
Next Generation Analysis System
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
NAGASH::ThreadPool Class Reference

a lightweight thread pool Modified from https://github.com/progschj/ThreadPool More...

#include "NAGASH::ThreadPool.h"

Public Member Functions

 ThreadPool (size_t)
 Construct the ThreadPool object with the given number of threads.
 
 ~ThreadPool ()
 Destruct the ThreadPool object, also joining all threads.
 
template<class F , class... Args>
auto enqueue (F &&f, Args &&...args) -> std::future< typename std::invoke_result_t< F, Args... > >
 Add a task to the thread pool.
 

Private Attributes

std::condition_variable condition
 
std::mutex queue_mutex
 
bool stop
 
std::queue< std::function< void()> > tasks
 
std::vector< std::thread > workers
 

Detailed Description

a lightweight thread pool Modified from https://github.com/progschj/ThreadPool

Definition at line 24 of file ThreadPool.h.

Constructor & Destructor Documentation

◆ ThreadPool()

NAGASH::ThreadPool::ThreadPool ( size_t  threads)
inline

Construct the ThreadPool object with the given number of threads.

Parameters
threadsnumber of threads to launch.

Definition at line 48 of file ThreadPool.h.

◆ ~ThreadPool()

NAGASH::ThreadPool::~ThreadPool ( )
inline

Destruct the ThreadPool object, also joining all threads.

Definition at line 106 of file ThreadPool.h.

Member Function Documentation

◆ enqueue()

template<class F , class... Args>
auto NAGASH::ThreadPool::enqueue ( F &&  f,
Args &&...  args 
) -> std::future<typename std::invoke_result_t<F, Args...>>

Add a task to the thread pool.

Template Parameters
Fcan be deduced by the compiler.
...Argscan be deduced by the compiler.
Parameters
fthe function to run.
...argsthe arguments to pass to the function.
Returns
the std::future of the function.

Definition at line 82 of file ThreadPool.h.

Member Data Documentation

◆ condition

std::condition_variable NAGASH::ThreadPool::condition
private

Definition at line 41 of file ThreadPool.h.

◆ queue_mutex

std::mutex NAGASH::ThreadPool::queue_mutex
private

Definition at line 40 of file ThreadPool.h.

◆ stop

bool NAGASH::ThreadPool::stop
private

Definition at line 42 of file ThreadPool.h.

◆ tasks

std::queue<std::function<void()> > NAGASH::ThreadPool::tasks
private

Definition at line 37 of file ThreadPool.h.

◆ workers

std::vector<std::thread> NAGASH::ThreadPool::workers
private

Definition at line 35 of file ThreadPool.h.


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