Commit 1e1e08a9 by FritzFlorian

Add yielding to scheduler loop.

We yield after num_thread failed steals in a row. This parameter can be tuned for better performance, but we stick to a sensible default just to prevent massive spinning.
parent 15c71232
Pipeline #1414 failed with stages
in 37 seconds
...@@ -68,6 +68,7 @@ void scheduler::work_thread_work_section() { ...@@ -68,6 +68,7 @@ void scheduler::work_thread_work_section() {
main_thread_starter_function_->run(); main_thread_starter_function_->run();
} }
unsigned int failed_steals = 0;
while (!work_section_done_) { while (!work_section_done_) {
PLS_ASSERT(my_task_manager.check_task_chain(), "Must start stealing with a clean task chain."); 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() { ...@@ -111,6 +112,12 @@ void scheduler::work_thread_work_section() {
stolen_task->is_synchronized_ = false; stolen_task->is_synchronized_ = false;
context_switcher::switch_context(std::move(stolen_task->continuation_)); context_switcher::switch_context(std::move(stolen_task->continuation_));
// We will continue execution in this line when we finished the stolen work. // 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();
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment