From 91913fba595e9f692cadf141ea0f0c29f789ed7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Wed, 13 Jul 2022 10:33:14 +0200 Subject: [PATCH] LibThreading: Add is_started state information to Thread Users can now determine whether a thread has been started or not. A started thread might also have already terminated. Implementation note: We *could* detect this with pthread APIs maybe, but this is much simpler. --- Userland/Libraries/LibThreading/Thread.cpp | 1 + Userland/Libraries/LibThreading/Thread.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Userland/Libraries/LibThreading/Thread.cpp b/Userland/Libraries/LibThreading/Thread.cpp index 7659793c29..d62684de98 100644 --- a/Userland/Libraries/LibThreading/Thread.cpp +++ b/Userland/Libraries/LibThreading/Thread.cpp @@ -45,6 +45,7 @@ void Threading::Thread::start() VERIFY(rc == 0); } dbgln("Started thread \"{}\", tid = {}", m_thread_name, m_tid); + m_started = true; } void Threading::Thread::detach() diff --git a/Userland/Libraries/LibThreading/Thread.h b/Userland/Libraries/LibThreading/Thread.h index 612403846d..dec19c248a 100644 --- a/Userland/Libraries/LibThreading/Thread.h +++ b/Userland/Libraries/LibThreading/Thread.h @@ -32,6 +32,7 @@ public: String thread_name() const { return m_thread_name; } pthread_t tid() const { return m_tid; } + bool is_started() const { return m_started; } private: explicit Thread(Function action, StringView thread_name = {}); @@ -39,6 +40,7 @@ private: pthread_t m_tid { 0 }; String m_thread_name; bool m_detached { false }; + bool m_started { false }; }; template