From 099b05380e7c02056bfce828dfde82acbce77baa Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 17 Sep 2022 22:35:42 +0200 Subject: [PATCH] Fix race condition. --- core/os/thread_pool.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/os/thread_pool.cpp b/core/os/thread_pool.cpp index a1a49056e..baa068df6 100644 --- a/core/os/thread_pool.cpp +++ b/core/os/thread_pool.cpp @@ -113,16 +113,17 @@ bool ThreadPool::is_working_no_lock() const { } bool ThreadPool::has_job(const Ref &job) { + _THREAD_SAFE_LOCK_ + for (int i = 0; i < _threads.size(); ++i) { ThreadPoolContext *context = _threads.get(i); if (context->job == job) { + _THREAD_SAFE_UNLOCK_ return true; } } - _THREAD_SAFE_LOCK_ - List>::Element *E = _queue.find(job); _THREAD_SAFE_UNLOCK_