UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
FThread Class Referencefinal

#include <Thread.h>

Public Types

enum  EForkable { Forkable , NonForkable }
 

Public Member Functions

 FThread ()
 
CORE_API FThread (TCHAR const *ThreadName, TUniqueFunction< void()> &&ThreadFunction, uint32 StackSize=0, EThreadPriority ThreadPriority=TPri_Normal, FThreadAffinity ThreadAffinity=FThreadAffinity(), EForkable IsForkable=NonForkable)
 
CORE_API 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
 
CORE_API FThreadoperator= (FThread &&Other)
 
CORE_API ~FThread ()
 
CORE_API bool IsJoinable () const
 
CORE_API void Join ()
 
CORE_API uint32 GetThreadId () const
 

Static Public Attributes

static constexpr uint32 InvalidThreadId = ~uint32(0)
 

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

Member Enumeration Documentation

◆ EForkable

Enumerator
Forkable 
NonForkable 

Constructor & Destructor Documentation

◆ FThread() [1/5]

FThread::FThread ( )
inline

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

◆ 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

◆ InvalidThreadId

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

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