summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-08-16 01:54:34 +0200
committerAndreas Kling <kling@serenityos.org>2021-08-16 02:22:42 +0200
commitc1c12497b56edbdbd02cb3f687a676f1c6a39cac (patch)
tree9d124ed795ad8f65d2d57baf11dd5aa9afd0ddcc /Kernel
parent29a58459ab0e432ccfe43528bc3bd61786e867b2 (diff)
downloadserenity-c1c12497b56edbdbd02cb3f687a676f1c6a39cac.zip
Kernel: Don't hold thread list lock while invoking ~Thread()
There is no need for this, and it can cause deadlocks if ~Thread() ends up doing something else that requires a lock (e.g ~Process())
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Thread.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp
index 59389476b1..506675abc7 100644
--- a/Kernel/Thread.cpp
+++ b/Kernel/Thread.cpp
@@ -39,13 +39,16 @@ SpinLockProtectedValue<Thread::GlobalList>& Thread::all_threads()
bool Thread::unref() const
{
- return all_threads().with([&](auto&) {
+ bool did_hit_zero = all_threads().with([&](auto&) {
if (deref_base())
return false;
m_global_thread_list_node.remove();
- delete this;
return true;
});
+
+ if (did_hit_zero)
+ delete this;
+ return did_hit_zero;
}
KResultOr<NonnullRefPtr<Thread>> Thread::try_create(NonnullRefPtr<Process> process)