mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:37:35 +00:00
LibThreading: Make Thread keep itself alive while its action is running
Previously, a `Thread` could be deleted while its action was running, even if it was running detached. By changing it to be atomically reference counted, and incrementing the count when starting the action, we can keep the Thread and its running action `Function` alive until it exits. Thus, detached `Thread` objects can be deleted by the thread creating them and allowed to die naturally.
This commit is contained in:
parent
71df0ee994
commit
aff64b6a03
2 changed files with 5 additions and 5 deletions
|
@ -8,6 +8,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/AtomicRefCounted.h>
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/DistinctNumeric.h>
|
||||
#include <AK/Function.h>
|
||||
|
@ -42,7 +43,7 @@ enum class ThreadState : u8 {
|
|||
};
|
||||
|
||||
class Thread final
|
||||
: public RefCounted<Thread>
|
||||
: public AtomicRefCounted<Thread>
|
||||
, public Weakable<Thread> {
|
||||
public:
|
||||
static NonnullRefPtr<Thread> construct(Function<intptr_t()> action, StringView thread_name = {})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue