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.
This commit is contained in:
Sebastian Ullrich 2023-12-12 03:01:40 +01:00 committed by GitHub
parent b120080b85
commit 78200b309f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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();
}
}