diff options
author | Tom <tomut@yahoo.com> | 2020-11-11 16:05:00 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-11-12 10:18:16 +0100 |
commit | 6b97118e89670f636e9c4de01b10cbab58dcc0db (patch) | |
tree | fc8412e71edad9d898fc57a2371d92ec0e9bb4c4 /Kernel/Thread.cpp | |
parent | 352e0196e1bdea59e0cba0a184fb06726f0206cd (diff) | |
download | serenity-6b97118e89670f636e9c4de01b10cbab58dcc0db.zip |
Kernel: Fix race during thread destruction if it is preempted
This fixes a lot of crashes in Bochs, which is more likely to
preempt thread destruction.
Diffstat (limited to 'Kernel/Thread.cpp')
-rw-r--r-- | Kernel/Thread.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index 1dd2c2862c..7de2263303 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -114,6 +114,17 @@ Thread::Thread(NonnullRefPtr<Process> process) Thread::~Thread() { + { + // We need to explicitly remove ourselves from the thread list + // here. We may get pre-empted in the middle of destructing this + // thread, which causes problems if the thread list is iterated. + // Specifically, if this is the last thread of a process, checking + // block conditions would access m_process, which would be in + // the middle of being destroyed. + ScopedSpinLock lock(g_scheduler_lock); + g_scheduler_data->thread_list_for_state(m_state).remove(*this); + } + ASSERT(!m_joiner); } |