diff options
author | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2024-04-08 17:37:00 +0200 |
---|---|---|
committer | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2024-04-10 18:47:41 +0200 |
commit | 71facbaa882494f5c3dccf6a799ce84dcd12e4c9 (patch) | |
tree | ed00c16859c4764d3fd8bb7f9e00efd86200984c | |
parent | b091162a90143df6aea04d0b4a3bb28d8bcf91a8 (diff) | |
download | redot-engine-71facbaa882494f5c3dccf6a799ce84dcd12e4c9.tar.gz |
WorkerThreadPool: Fix data race
-rw-r--r-- | core/object/worker_thread_pool.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/core/object/worker_thread_pool.cpp b/core/object/worker_thread_pool.cpp index ef3d315e4b..4ec0ab4df2 100644 --- a/core/object/worker_thread_pool.cpp +++ b/core/object/worker_thread_pool.cpp @@ -60,11 +60,13 @@ void WorkerThreadPool::_process_task(Task *p_task) { // its pre-created threads can't have ScriptServer::thread_enter() called on them early. // Therefore, we do it late at the first opportunity, so in case the task // about to be run uses scripting, guarantees are held. + task_mutex.lock(); if (!curr_thread.ready_for_scripting && ScriptServer::are_languages_initialized()) { + task_mutex.unlock(); ScriptServer::thread_enter(); + task_mutex.lock(); curr_thread.ready_for_scripting = true; } - task_mutex.lock(); p_task->pool_thread_index = pool_thread_index; prev_task = curr_thread.current_task; curr_thread.current_task = p_task; |