From bfb3fc58dd6e2ffd91c21f55c53e95f02e4bbc75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Thu, 10 Nov 2022 20:59:39 +0100 Subject: [PATCH] Kernel: Allow dead threads to be joined Joining dead threads is allowed for two main reasons: - Thread join behavior should not be racy when a thread is joined and exiting at roughly the same time. This is common behavior when threads are given a signal to end (meaning they are going to exit ASAP) and then joined. - POSIX requires that exited threads are joinable (at least, there is no language in the specification forbidding it). The behavior is still well-defined; e.g. it doesn't allow a dead detached thread to be joined or a thread to be joined more than once. --- Kernel/Thread.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Kernel/Thread.h b/Kernel/Thread.h index cbb9e9bdd7..51914a9b2a 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -824,7 +824,12 @@ public: return EDEADLK; SpinlockLocker lock(m_lock); - if (!m_is_joinable || state() == Thread::State::Dead) + + // Joining dead threads is allowed for two main reasons: + // - Thread join behavior should not be racy when a thread is joined and exiting at roughly the same time. + // This is common behavior when threads are given a signal to end (meaning they are going to exit ASAP) and then joined. + // - POSIX requires that exited threads are joinable (at least, there is no language in the specification forbidding it). + if (!m_is_joinable || state() == Thread::State::Invalid) return EINVAL; add_blocker();