Skip to content

Commit

Permalink
Merge pull request #76999 from RandomShaper/fix_wtp_exit
Browse files Browse the repository at this point in the history
`WorkerThreadPool`: Handle exit signal in the tentative scheduling done during waits
  • Loading branch information
akien-mga committed May 12, 2023
2 parents e0bbb83 + 123ba9d commit 8dd48a9
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions core/object/worker_thread_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,20 @@ void WorkerThreadPool::wait_for_task_completion(TaskID p_task_id) {

if (index) {
// We are an actual process thread, we must not be blocked so continue processing stuff if available.
bool must_exit = false;
while (true) {
if (task->done_semaphore.try_wait()) {
// If done, exit
break;
}
if (task_available_semaphore.try_wait()) {
// Solve tasks while they are around.
_process_task_queue();
continue;
if (!must_exit && task_available_semaphore.try_wait()) {
if (exit_threads) {
must_exit = true;
} else {
// Solve tasks while they are around.
_process_task_queue();
continue;
}
}
OS::get_singleton()->delay_usec(1); // Microsleep, this could be converted to waiting for multiple objects in supported platforms for a bit more performance.
}
Expand Down

0 comments on commit 8dd48a9

Please sign in to comment.