Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
FThread Class Referencefinal

#include <Thread.h>

+ Collaboration diagram for FThread:

Public Types

enum  EForkable { Forkable , NonForkable }
 

Public Member Functions

 FThread ()
 
 FThread (TCHAR const *ThreadName, TUniqueFunction< void()> &&ThreadFunction, uint32 StackSize=0, EThreadPriority ThreadPriority=TPri_Normal, FThreadAffinity ThreadAffinity=FThreadAffinity(), EForkable IsForkable=NonForkable)
 
 FThread (TCHAR const *ThreadName, TUniqueFunction< void()> &&ThreadFunction, TUniqueFunction< void()> &&SingleThreadTickFunction, uint32 StackSize=0, EThreadPriority ThreadPriority=TPri_Normal, FThreadAffinity ThreadAffinity=FThreadAffinity(), EForkable IsForkable=NonForkable)
 
 FThread (const FThread &)=delete
 
FThreadoperator= (const FThread &)=delete
 
 FThread (FThread &&)=default
 
FThreadoperator= (FThread &&Other)
 
 ~FThread ()
 
bool IsJoinable () const
 
void Join ()
 
uint32 GetThreadId () const
 

Static Public Attributes

static constexpr uint32 InvalidThreadId = ~uint32(0)
 

Private Attributes

TSharedPtr< class FThreadImpl, ESPMode::ThreadSafeImpl
 

Detailed Description

Simple API for system threads. Before using, please make sure you really need a new system thread. By default and in the majority of cases parallel processing should be done by TaskGraph. For richer functionality check FRunnable/FRunnableThread. It's up to user to provide a way to notify the thread function to exit on demand. Before destroying the instance it must be either Joined or Detached. Example: FThread Thread{TEXT("New thread"), []() { do_something_important(); }}; // ... continue in the caller thread Thread.Join(); For more verbose example check TestTypicalUseCase in ThreadTest.cpp

Definition at line 23 of file Thread.h.

Member Enumeration Documentation

◆ EForkable

Enumerator
Forkable 
NonForkable 

Definition at line 27 of file Thread.h.

Constructor & Destructor Documentation

◆ FThread() [1/5]

FThread::FThread ( )
inline

Creates new "empty" thread object that doesn't represent a system thread

Definition at line 32 of file Thread.h.

◆ FThread() [2/5]

FThread::FThread ( TCHAR const * ThreadName,
TUniqueFunction< void()> && ThreadFunction,
uint32 StackSize = 0,
EThreadPriority ThreadPriority = TPri_Normal,
FThreadAffinity ThreadAffinity = FThreadAffinity(),
EForkable IsForkable = NonForkable )

Creates and immediately starts a new system thread that will execute ThreadFunction argument. Can return before the thread is actually started or when it already finished execution.

Parameters
ThreadNameName of the thread
ThreadFunctionThe function that will be executed by the newly created thread
StackSizeThe size of the stack to create. 0 means use the current thread's stack size
ThreadPriorityTells the thread whether it needs to adjust its priority or not. Defaults to normal priority
ThreadAffinityTells the thread whether it needs to adjust its affinity or not. Defaults to no affinity
IsForkableTells the thread whether it can be forked. Defaults to NonForkable

◆ FThread() [3/5]

FThread::FThread ( TCHAR const * ThreadName,
TUniqueFunction< void()> && ThreadFunction,
TUniqueFunction< void()> && SingleThreadTickFunction,
uint32 StackSize = 0,
EThreadPriority ThreadPriority = TPri_Normal,
FThreadAffinity ThreadAffinity = FThreadAffinity(),
EForkable IsForkable = NonForkable )

◆ FThread() [4/5]

FThread::FThread ( const FThread & )
delete

◆ FThread() [5/5]

FThread::FThread ( FThread && )
default

◆ ~FThread()

FThread::~FThread ( )

Destructor asserts if the instance is not joined or detached.

Member Function Documentation

◆ GetThreadId()

uint32 FThread::GetThreadId ( ) const
Returns
Thread ID for this thread

◆ IsJoinable()

bool FThread::IsJoinable ( ) const

Checks if the thread object identifies an active thread of execution. A thread that has finished executing code, but has not yet been joined is still considered an active thread of execution and is therefore joinable.

See also
Join

◆ Join()

void FThread::Join ( )

Blocks the current thread until the thread identified by this finishes its execution. The completion of the thread identified by this synchronizes with the corresponding successful return from Join(). No synchronization is performed on this itself. Concurrently calling Join() on the same FThread object from multiple threads constitutes a data race that results in undefined behavior.

See also
IsJoinable

◆ operator=() [1/2]

FThread & FThread::operator= ( const FThread & )
delete

◆ operator=() [2/2]

FThread & FThread::operator= ( FThread && Other)

Move assignment operator. Asserts if the instance is joinable.

Member Data Documentation

◆ Impl

Definition at line 118 of file Thread.h.

◆ InvalidThreadId

constexpr uint32 FThread::InvalidThreadId = ~uint32(0)
staticconstexpr

Definition at line 99 of file Thread.h.


The documentation for this class was generated from the following file: