UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Thread.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "HAL/Platform.h"
9
23class FThread final
24{
25public:
26 // indicates if the thread should be forked in case the owning process is forked
28
33 {}
34
46 TCHAR const* ThreadName,
47 TUniqueFunction<void()>&& ThreadFunction,
48 uint32 StackSize = 0,
49 EThreadPriority ThreadPriority = TPri_Normal,
52 );
53
54 // with SingleThreadTickFunction that will be executed every frame if running with `-nothreading
55 // (FPlatformProcess::SupportsMultithreading() == false)
57 TCHAR const* ThreadName,
58 TUniqueFunction<void()>&& ThreadFunction,
59 TUniqueFunction<void()>&& SingleThreadTickFunction,
60 uint32 StackSize = 0,
61 EThreadPriority ThreadPriority = TPri_Normal,
64 );
65
66 // non-copyable
67 FThread(const FThread&) = delete;
68 FThread& operator=(const FThread&) = delete;
69
70 FThread(FThread&&) = default;
76
81
88 CORE_API bool IsJoinable() const;
89
97 CORE_API void Join();
98
99 static constexpr uint32 InvalidThreadId = ~uint32(0);
100
105
106#if 0 // disabled as it doesn't work as intended
107
113 CORE_API void Detach();
114
115#endif
116
117private:
118 TSharedPtr<class FThreadImpl, ESPMode::ThreadSafe> Impl; // "shared" with `FThreadImpl::Self`
119};
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
EThreadPriority
Definition GenericPlatformAffinity.h:26
@ TPri_Normal
Definition GenericPlatformAffinity.h:27
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Thread.h:24
CORE_API bool IsJoinable() const
Definition Thread.cpp:148
static constexpr uint32 InvalidThreadId
Definition Thread.h:99
EForkable
Definition Thread.h:27
@ Forkable
Definition Thread.h:27
@ NonForkable
Definition Thread.h:27
FThread(const FThread &)=delete
FThread(FThread &&)=default
CORE_API uint32 GetThreadId() const
Definition Thread.cpp:160
CORE_API ~FThread()
Definition Thread.cpp:143
CORE_API void Join()
Definition Thread.cpp:153
FThread & operator=(const FThread &)=delete
FThread()
Definition Thread.h:32
Definition SharedPointer.h:692
Definition FunctionFwd.h:19
Definition ExpressionParserTypes.h:21
Definition PlatformAffinity.h:10