1 #include "nta/ThreadPool.h"
6 m_available(num_threads) {
8 for (
size_t id = 0;
id < num_threads;
id++) {
13 for (
size_t i = 0; i <
m_workers.size(); i++) {
20 for (
size_t i = 0; i <
m_workers.size(); i++) {
69 std::lock_guard<std::mutex> lg(
m_empty.m);
72 ThreadPool::~ThreadPool() {
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.
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.
void schedule(const Thunk &thunk)
Schedules a function to be executed.
void worker_func(size_t wid)
Function run by worker threads.
std::thread m_dispatch_thread
The thread for managing the pool.
std::vector< worker > m_workers
The workers.