jubilant-funicular
|
Collection of threads for running scheduled functions. More...
#include <ThreadPool.h>
Classes | |
struct | worker |
One thread available to the pool. More... | |
Public Member Functions | |
ThreadPool (size_t num_threads) | |
Constructs a ThreadPool with specified number of threads. | |
void | schedule (const Thunk &thunk) |
Schedules a function to be executed. | |
void | wait () |
Waits for all scheduled functions to finish execution. | |
ThreadPool (const ThreadPool &)=delete | |
ThreadPool & | operator= (const ThreadPool &)=delete |
Private Member Functions | |
void | dispatcher () |
Function run by dispatch thread. More... | |
void | worker_func (size_t wid) |
Function run by worker threads. | |
size_t | getAvailableWorker () |
Returns id of an available worker. | |
bool | allWorkFinished () |
Returns whether or not all work is finished. | |
Private Attributes | |
struct { | |
std::condition_variable_any | cv |
std::mutex | m |
} | m_empty |
Used to keep track of when the pool is empty. | |
std::vector< worker > | m_workers |
The workers. | |
std::atomic< bool > | m_kill |
Sign to kill the pool. | |
Semaphore | m_scheduled |
Record of scheduled workers. | |
Semaphore | m_available |
Record of available workers. | |
std::queue< Thunk > | m_funcs |
The functions to be executed. | |
std::thread | m_dispatch_thread |
The thread for managing the pool. | |
Collection of threads for running scheduled functions.
Definition at line 36 of file ThreadPool.h.
|
private |
Function run by dispatch thread.
Definition at line 28 of file ThreadPool.cpp.
Referenced by ThreadPool().