mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
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.
This commit is contained in:
parent
b6af5eaa72
commit
5ad24156ce
Notes:
sideshowbarker
2024-07-17 02:28:18 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/5ad24156ce Pull-request: https://github.com/SerenityOS/serenity/pull/19016 Reviewed-by: https://github.com/gmta ✅
1 changed files with 4 additions and 4 deletions
|
@ -123,11 +123,11 @@ void Thread::detach()
|
||||||
auto expected = Threading::ThreadState::Running;
|
auto expected = Threading::ThreadState::Running;
|
||||||
// This code might race with the other thread exiting.
|
// This code might race with the other thread exiting.
|
||||||
if (!m_state.compare_exchange_strong(expected, Threading::ThreadState::Detached)) {
|
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)
|
if (expected == Threading::ThreadState::Exited)
|
||||||
dbgln("Thread logic bug: {} is being detached after having exited!", this);
|
return;
|
||||||
else
|
|
||||||
dbgln("Thread logic bug: trying to detach {} which is not in the Started state, but state {}!", this, expected);
|
// 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();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue