The ThreadPool
Class Reference
Class managing a pool of worker threads. More...
Declaration
Included Headers
Public Constructors Index
ThreadPool (std::size_t N=1) | |
start N threads in the thread pool. More... | |
ThreadPool (const ThreadPool &)=delete | |
ThreadPool (ThreadPool &&)=delete | |
Public Destructor Index
~ThreadPool () | |
deletes the thread pool by finishing all threads More... | |
Public Operators Index
ThreadPool & | operator= (const ThreadPool &)=delete |
ThreadPool & | operator= (ThreadPool &&)=delete |
Public Member Functions Index
template <class F, typename ... Args> | |
auto | queue (F &&f, Args &&... args) -> std::future< decltype(f(args...))> |
Queue the callable function f for the threads to execute. More... | |
void | finish () |
finish enques a "stop the thread" message for every thread, then waits for them to finish More... | |
Private Member Functions Index
void | threadTask () |
Private Member Attributes Index
std::mutex | m_mutex |
std::condition_variable | m_cond |
std::deque< std::function< void()> > | m_work |
std::vector< std::future< void > > | m_finished |
Description
Class managing a pool of worker threads.
Work can be queued by passing a function to queue(). A future will be returned that can be used to obtain the result of the function after execution.
Usage example:
Definition at line 47 of file threadpool.h.
Public Constructors
ThreadPool()
| inline |
start N threads in the thread pool.
Definition at line 51 of file threadpool.h.
References m_finished and threadTask.
Referenced by operator=, operator=, ThreadPool and ThreadPool.
ThreadPool()
| delete |
Definition at line 69 of file threadpool.h.
Reference ThreadPool.
ThreadPool()
| delete |
Definition at line 71 of file threadpool.h.
Reference ThreadPool.
Public Destructor
~ThreadPool()
| inline |
deletes the thread pool by finishing all threads
Definition at line 65 of file threadpool.h.
Reference finish.
Public Operators
operator=()
| delete |
Definition at line 70 of file threadpool.h.
Reference ThreadPool.
operator=()
| delete |
Definition at line 72 of file threadpool.h.
Reference ThreadPool.
Public Member Functions
finish()
| inline |
finish enques a "stop the thread" message for every thread, then waits for them to finish
Definition at line 100 of file threadpool.h.
References m_cond, m_finished, m_mutex and m_work.
Referenced by ~ThreadPool.
queue()
| inline |
Queue the callable function f for the threads to execute.
A future of the return type of the function is returned to capture the result.
Definition at line 77 of file threadpool.h.
References m_cond, m_mutex and m_work.
Referenced by computeTooltipTexts, FormulaManager::createFormulasTexFile, generateDocsForClassList, generateFileDocs, generateFileSources, generateJSTreeFiles, generateNamespaceClassDocs, parseFilesMultiThreading and writeJavaScriptSearchIndex.
Private Member Functions
threadTask()
| inline |
Definition at line 116 of file threadpool.h.
References m_cond, m_mutex and m_work.
Referenced by ThreadPool.
Private Member Attributes
m_cond
|
Definition at line 142 of file threadpool.h.
Referenced by finish, queue and threadTask.
m_finished
|
Definition at line 148 of file threadpool.h.
Referenced by finish and ThreadPool.
m_mutex
|
Definition at line 141 of file threadpool.h.
Referenced by finish, queue and threadTask.
m_work
|
Definition at line 145 of file threadpool.h.
Referenced by finish, queue and threadTask.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus by Doxygen 1.14.0.