diff --git a/lib/pls/src/internal/scheduling/scheduler.cpp b/lib/pls/src/internal/scheduling/scheduler.cpp index 484337a..f3d9773 100644 --- a/lib/pls/src/internal/scheduling/scheduler.cpp +++ b/lib/pls/src/internal/scheduling/scheduler.cpp @@ -68,6 +68,7 @@ void scheduler::work_thread_work_section() { main_thread_starter_function_->run(); } + unsigned int failed_steals = 0; while (!work_section_done_) { PLS_ASSERT(my_task_manager.check_task_chain(), "Must start stealing with a clean task chain."); @@ -111,6 +112,12 @@ void scheduler::work_thread_work_section() { stolen_task->is_synchronized_ = false; context_switcher::switch_context(std::move(stolen_task->continuation_)); // We will continue execution in this line when we finished the stolen work. + failed_steals = 0; + } else { + failed_steals++; + if (failed_steals >= num_threads) { + base::this_thread::yield(); + } } } }