Simple API for system threads. 更多...
#include <Thread.h>
Public 成员函数 | |
| FThread () | |
| Creates new "empty" thread object that doesn't represent a system thread | |
| FThread (TCHAR const *ThreadName, TUniqueFunction< void()> &&ThreadFunction, uint32 StackSize=0, EThreadPriority ThreadPriority=TPri_Normal, uint64 ThreadAffinityMask=FPlatformAffinity::GetNoAffinityMask()) | |
Creates and immediately starts a new system thread that will execute ThreadFunction argument. 更多... | |
| uint32 | GetThreadId () const |
| bool | IsJoinable () const |
| Checks if the thread object identifies an active thread of execution. 更多... | |
| void | Join () |
Blocks the current thread until the thread identified by this finishes its execution. 更多... | |
| FThread & | operator= (FThread &&Other) |
| Move assignment operator. 更多... | |
| ~FThread () | |
| Destructor asserts if the instance is not joined or detached. | |
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
| FThread::FThread | ( | TCHAR const * | ThreadName, |
| TUniqueFunction< void()> && | ThreadFunction, | ||
| uint32 | StackSize = 0, |
||
| EThreadPriority | ThreadPriority = TPri_Normal, |
||
| uint64 | ThreadAffinityMask = FPlatformAffinity::GetNoAffinityMask() |
||
| ) |
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.
| ThreadName | Name of the thread |
| ThreadFunction | The function that will be executed by the newly created thread |
| StackSize | The size of the stack to create. 0 means use the current thread's stack size |
| ThreadPriority | Tells the thread whether it needs to adjust its priority or not. Defaults to normal priority |
| uint32 FThread::GetThreadId | ( | ) | const |
| 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.
| 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.
Move assignment operator.
Asserts if the instance is joinable.