1 #ifndef NTA_THREADPOOL_H_INCLUDED
2 #define NTA_THREADPOOL_H_INCLUDED
9 #include <condition_variable>
11 typedef std::function<void(
void)> Thunk;
21 std::condition_variable_any m_cv;
63 std::condition_variable_any cv;
93 #endif // NTA_THREADPOOL_H_INCLUDED
Semaphore(int value=0)
Constructs Semaphore with given value.
Thunk thunk
The function the worker is currently scheduled to execute.
std::queue< Thunk > m_funcs
The functions to be executed.
std::atomic< bool > m_kill
Sign to kill the pool.
Semaphore m_scheduled
Record of scheduled workers.
void wait()
Halts until value of Semaphore is > 0.
void wait()
Waits for all scheduled functions to finish execution.
Semaphore m_available
Record of available workers.
struct nta::utils::ThreadPool::@6 m_empty
Used to keep track of when the pool is empty.
int m_value
The number of resources available.
One thread available to the pool.
ThreadPool(size_t num_threads)
Constructs a ThreadPool with specified number of threads.
void signal()
Increments value of Semaphore.
bool allWorkFinished()
Returns whether or not all work is finished.
size_t getAvailableWorker()
Returns id of an available worker.
void dispatcher()
Function run by dispatch thread.
std::mutex m_mutex
Thread safety stuff.
void schedule(const Thunk &thunk)
Schedules a function to be executed.
Collection of threads for running scheduled functions.
void worker_func(size_t wid)
Function run by worker threads.
std::thread t
The thread owned by the worker.
std::thread m_dispatch_thread
The thread for managing the pool.
std::atomic< bool > free
Whether or not the worker is free to take on a new function.
std::vector< worker > m_workers
The workers.