summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-05-24 06:54:46 -0400
committerJelle Raaijmakers <jelle@gmta.nl>2023-05-24 16:45:25 +0200
commit5ad24156ced25d025e9ab4ae191d0bd8f5f5bf10 (patch)
tree0a40b1dd9d8648d56696c3a597e663dd4ab22e93
parentb6af5eaa72c671dd4136c0c9f9e2a3b6996b1434 (diff)
downloadserenity-5ad24156ced25d025e9ab4ae191d0bd8f5f5bf10.zip
LibThreading: Do not crash when detaching from an already-exited thread
Contrary to the log message that was shown, it is not decidedly a logic error to detach a thread that has exited. Even in the simple unit tests we have, it's possibly for the thread to run and exit in between the time it takes for our call to Thread::start() to complete and Thread::detach() to run. This is often seen on CI.
-rw-r--r--Userland/Libraries/LibThreading/Thread.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/Userland/Libraries/LibThreading/Thread.cpp b/Userland/Libraries/LibThreading/Thread.cpp
index 15dcd9ec39..668a8f8ccf 100644
--- a/Userland/Libraries/LibThreading/Thread.cpp
+++ b/Userland/Libraries/LibThreading/Thread.cpp
@@ -123,11 +123,11 @@ void Thread::detach()
auto expected = Threading::ThreadState::Running;
// This code might race with the other thread exiting.
if (!m_state.compare_exchange_strong(expected, Threading::ThreadState::Detached)) {
- // Always report a precise error before crashing. These kinds of bugs are hard to reproduce.
if (expected == Threading::ThreadState::Exited)
- dbgln("Thread logic bug: {} is being detached after having exited!", this);
- else
- dbgln("Thread logic bug: trying to detach {} which is not in the Started state, but state {}!", this, expected);
+ return;
+
+ // Always report a precise error before crashing. These kinds of bugs are hard to reproduce.
+ dbgln("Thread logic bug: trying to detach {} in state {}, which is neither Started nor Exited", this, expected);
VERIFY_NOT_REACHED();
}