Navigation
API > API/Runtime > API/Runtime/Core
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](API\Runtime\Core\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 Join_ed or Detach_ed. 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
| Name | FThread |
| Type | class |
| Header File | /Engine/Source/Runtime/Core/Public/HAL/Thread.h |
| Include Path | #include "HAL/Thread.h" |
Syntax
class FThread
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
FThread () |
Creates new "empty" thread object that doesn't represent a system thread | HAL/Thread.h | |
FThread
(
TCHAR const* ThreadName, |
Creates and immediately starts a new system thread that will execute `ThreadFunction_ argument. | HAL/Thread.h |
Destructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
~FThread() |
Destructor asserts if the instance is not joined or detached. | HAL/Thread.h |
Enums
Public
| Name | Remarks |
|---|---|
| EForkable | Indicates if the thread should be forked in case the owning process is forked |
Constants
| Name | Type | Remarks | Include Path |
|---|---|---|---|
| InvalidThreadId | uint32 | HAL/Thread.h |
Variables
Protected
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| Impl | TSharedPtr< class FThreadImpl, ESPMode::ThreadSafe > | HAL/Thread.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
uint32 GetThreadId() |
HAL/Thread.h | ||
bool IsJoinable () |
Checks if the thread object identifies an active thread of execution. | HAL/Thread.h | |
void Join () |
Blocks the current thread until the thread identified by `this_ finishes its execution. | HAL/Thread.h |
Operators
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
| With SingleThreadTickFunction that will be executed every frame if running with `-nothreading / (FPlatformProcess::SupportsMultithreading() == false) FThread( TCHAR const* ThreadName, TUniqueFunction |
HAL/Thread.h |