1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:38:11 +00:00

LibThreading: Add new detach() API to Thread

Sometimes you don't care about `joining()` the result of a thread. The
underlying pthread implementation already existed for detaching and
now we expose it to the higher level API.
This commit is contained in:
Spencer Dixon 2021-07-02 08:05:07 -04:00 committed by Andreas Kling
parent 5666809889
commit 48731e9f17
2 changed files with 14 additions and 1 deletions

View file

@ -20,7 +20,7 @@ Threading::Thread::Thread(Function<intptr_t()> action, StringView thread_name)
Threading::Thread::~Thread()
{
if (m_tid) {
if (m_tid && !m_detached) {
dbgln("Destroying thread \"{}\"({}) while it is still running!", m_thread_name, m_tid);
[[maybe_unused]] auto res = join();
}
@ -46,3 +46,13 @@ void Threading::Thread::start()
}
dbgln("Started thread \"{}\", tid = {}", m_thread_name, m_tid);
}
void Threading::Thread::detach()
{
VERIFY(!m_detached);
int rc = pthread_detach(m_tid);
VERIFY(rc == 0);
m_detached = true;
}