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.
This commit is contained in:
kleines Filmröllchen 2022-11-10 20:59:39 +01:00 committed by Andrew Kaster
parent 8997d825d5
commit bfb3fc58dd

View file

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