mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
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.
This commit is contained in:
parent
352e0196e1
commit
6b97118e89
Notes:
sideshowbarker
2024-07-19 01:25:52 +09:00
Author: https://github.com/tomuta Commit: https://github.com/SerenityOS/serenity/commit/6b97118e896 Pull-request: https://github.com/SerenityOS/serenity/pull/4055 Reviewed-by: https://github.com/awesomekling
1 changed files with 11 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue