From d73965e887096029ba6141ac0018a7a20c9d1172 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Wed, 25 Sep 2019 12:50:36 +0200 Subject: [PATCH] fix tear-down of worker --- lib/src/common/thread_pool.cc | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/src/common/thread_pool.cc b/lib/src/common/thread_pool.cc index 122fec2ec..bb9e06b3d 100644 --- a/lib/src/common/thread_pool.cc +++ b/lib/src/common/thread_pool.cc @@ -19,9 +19,10 @@ * */ +#include "srslte/common/thread_pool.h" #include +#include #include -#include "srslte/common/thread_pool.h" #define DEBUG 0 #define debug_thread(fmt, ...) do { if(DEBUG) printf(fmt, __VA_ARGS__); } while(0) @@ -310,22 +311,22 @@ void task_thread_pool::start(int32_t prio, uint32_t mask) void task_thread_pool::stop() { std::unique_lock lock(queue_mutex); - running = false; - do { - nof_workers_running = 0; - // next worker that is still running - for (worker_t& w : workers) { - if (w.is_running()) { - nof_workers_running++; - } + running = false; + nof_workers_running = 0; + // next worker that is still running + for (worker_t& w : workers) { + if (w.is_running()) { + nof_workers_running++; } - if (nof_workers_running > 0) { - lock.unlock(); - cv_empty.notify_all(); - lock.lock(); + } + if (nof_workers_running > 0) { + lock.unlock(); + cv_empty.notify_all(); + lock.lock(); + while (nof_workers_running > 0) { cv_exit.wait(lock); } - } while (nof_workers_running > 0); + } } void task_thread_pool::push_task(const task_t& task)