From 7c968a9543b41470fadc7ae5e04607f3f85833fb Mon Sep 17 00:00:00 2001 From: drslebedev Date: Fri, 24 Nov 2023 12:33:01 +0100 Subject: [PATCH] Fix the probem in Scheduler when using only one thread with executionPolicy=multiThreaded --- core/include/gnuradio-4.0/Scheduler.hpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/core/include/gnuradio-4.0/Scheduler.hpp b/core/include/gnuradio-4.0/Scheduler.hpp index 57bd6c10..9e00d4d7 100644 --- a/core/include/gnuradio-4.0/Scheduler.hpp +++ b/core/include/gnuradio-4.0/Scheduler.hpp @@ -138,15 +138,16 @@ class SchedulerBase { void poolWorker(const std::function &work, std::size_t n_batches) { - auto &profiler_handler = _profiler.forThisThread(); + auto &profiler_handler = _profiler.forThisThread(); - uint32_t done = 0; - uint32_t progress_count = 0; + uint32_t done = 0; + uint32_t progress_count = 0; while (done < n_batches && !_stop_requested) { auto pe = profiler_handler.startCompleteEvent("scheduler_base.work"); bool something_happened = work().status == work::Status::OK; pe.finish(); - uint64_t progress_local, progress_new; + uint64_t progress_local = 0ULL; + uint64_t progress_new = 0ULL; if (something_happened) { // something happened in this thread => increase progress and reset done count do { progress_local = _progress.load(); @@ -168,11 +169,12 @@ class SchedulerBase { } } while (!_progress.compare_exchange_strong(progress_local, progress_new)); _progress.notify_all(); - if (progress_count == progress_count_old && done < n_batches) { + if (progress_count == progress_count_old && done + 1 < n_batches) { _progress.wait(progress_new); } } } // while (done < n_batches) + _running_threads.fetch_sub(1); _running_threads.notify_all(); }