55 if (m_exception_ptr !=
nullptr) {
60 task_ptr = Euclid::make_unique<ThreadPool::Task>(
m_queue.get().front());
98 : m_worker_run_flags(thread_count)
99 , m_worker_sleeping_flags(thread_count)
100 , m_worker_done_flags(thread_count)
102 for (
unsigned int i = 0; i < thread_count; ++i) {
115 for (
auto& flag : worker_flags) {
154 bool queue_is_empty =
false;
155 while (!queue_is_empty) {
161 queue_is_empty =
m_queue.empty();
163 if (!queue_is_empty) {
std::reference_wrapper< std::mutex > m_queue_mutex
std::reference_wrapper< std::atomic< bool > > m_run_flag
std::reference_wrapper< std::atomic< bool > > m_sleeping_flag
std::reference_wrapper< std::deque< ThreadPool::Task > > m_queue
std::reference_wrapper< std::atomic< bool > > m_done_flag
unsigned int m_empty_queue_wait_time
std::reference_wrapper< std::exception_ptr > m_exception_ptr
void submit(Task task)
Submit a task to be executed.
std::deque< Task > m_queue
size_t running() const
Return the number of running tasks.
void block(bool throw_on_exception=true)
std::vector< std::atomic< bool > > m_worker_sleeping_flags
size_t queued() const
Return the number of queued tasks.
unsigned int m_empty_queue_wait_time
std::vector< std::thread > m_workers
std::vector< std::atomic< bool > > m_worker_run_flags
std::vector< std::atomic< bool > > m_worker_done_flags
bool checkForException(bool rethrow=false)
Checks if any task has thrown an exception and optionally rethrows it.
std::exception_ptr m_exception_ptr
size_t activeThreads() const
Return the number of active workers (either running or sleeping)
ThreadPool(unsigned int thread_count=std::thread::hardware_concurrency(), unsigned int empty_queue_wait_time=50)
Constructs a new ThreadPool.
T current_exception(T... args)
T emplace_back(T... args)
T rethrow_exception(T... args)