From 7a70b36c8b86bb60be194102a7b5f2697f951d11 Mon Sep 17 00:00:00 2001 From: Cthulhu-throwaway <96153783+Cthulhu-throwaway@users.noreply.github.com> Date: Fri, 29 Apr 2022 09:29:07 -0300 Subject: [PATCH] (Threaded Tasks) Fix race condition at task_queue_wait (#13898) --- libretro-common/queues/task_queue.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libretro-common/queues/task_queue.c b/libretro-common/queues/task_queue.c index 9bf680c7c2..87149c51cd 100644 --- a/libretro-common/queues/task_queue.c +++ b/libretro-common/queues/task_queue.c @@ -423,6 +423,13 @@ static void retro_task_threaded_wait(retro_task_condition_fn_t cond, void* data) slock_lock(running_lock); wait = (tasks_running.front && !tasks_running.front->when); slock_unlock(running_lock); + + if (!wait) + { + slock_lock(finished_lock); + wait = (tasks_finished.front && !tasks_finished.front->when); + slock_unlock(finished_lock); + } } while (wait && (!cond || cond(data))); }