From 78200b309f63b30e855313a15e25391efcfe6974 Mon Sep 17 00:00:00 2001 From: Sebastian Ullrich Date: Tue, 12 Dec 2023 03:01:40 +0100 Subject: [PATCH] fix: `run_task`/`deactivate_task` race condition on `m_imp->m_closure` (#2959) Fixes #2853, unblocking my work before I get to refactoring this part of the task manager. --- src/runtime/object.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/runtime/object.cpp b/src/runtime/object.cpp index 1e12765686..397515ac78 100644 --- a/src/runtime/object.cpp +++ b/src/runtime/object.cpp @@ -714,8 +714,12 @@ class task_manager { resolve_core(t, v); } else { // `bind` task has not finished yet, re-add as dependency of nested task + // NOTE: closure MUST be extracted before unlocking the mutex as otherwise + // another thread could deactivate the task and empty `m_clousure` in + // between. + object * c = t->m_imp->m_closure; lock.unlock(); - add_dep(lean_to_task(closure_arg_cptr(t->m_imp->m_closure)[0]), t); + add_dep(lean_to_task(closure_arg_cptr(c)[0]), t); lock.lock(); } }