Skip to content

Commit

Permalink
Fix the probem in Scheduler when using only one thread with execution…
Browse files Browse the repository at this point in the history
…Policy=multiThreaded
  • Loading branch information
drslebedev committed Nov 24, 2023
1 parent 52f48e9 commit 7c968a9
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions core/include/gnuradio-4.0/Scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,16 @@ class SchedulerBase {

void
poolWorker(const std::function<work::Result()> &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();
Expand All @@ -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();
}
Expand Down

0 comments on commit 7c968a9

Please sign in to comment.