![]() |
ezEngine Release 26.3
|
Contains general thread functions. More...
#include <ThreadUtils.h>
Static Public Member Functions | |
| static void | YieldTimeSlice () |
| Suspends execution of the current thread and yields the remaining time slice to other threads. | |
| static void | YieldHardwareThread () |
| Yields execution to other hardware threads on the same physical processor core. | |
| static void | Sleep (const ezTime &duration) |
| Suspends the execution of the current thread for the given amount of time. | |
| static bool | IsMainThread () |
| Checks if the current thread is the main thread. | |
| static ezThreadID | GetCurrentThreadID () |
| Returns a unique identifier for the currently executing thread. | |
Contains general thread functions.
|
static |
Returns a unique identifier for the currently executing thread.
The returned ID is guaranteed to be unique among all currently running threads, but may be reused after a thread terminates. Thread IDs should not be stored long-term or used for cross-process communication. Primarily useful for debugging, logging, and temporary thread identification.
|
static |
Checks if the current thread is the main thread.
The main thread is defined as the thread that initialized the Foundation library. This is useful for assertions and ensuring certain operations only happen on the main thread (e.g., UI operations, single-threaded subsystem access). Returns true only for the thread that called Foundation startup.
|
static |
Suspends the execution of the current thread for the given amount of time.
The actual sleep duration may be longer than requested due to OS scheduling granularity and system load. Precision varies by platform but is typically around 1-15ms. For high-precision timing, consider using busy-wait loops with YieldTimeSlice() for very short delays, though this consumes more CPU. Avoid using Sleep() in performance-critical code paths.
|
static |
Yields execution to other hardware threads on the same physical processor core.
This is a hint to the processor to allow other hardware threads (hyperthreads) on the same core to execute. Only useful on processors with simultaneous multithreading (SMT/hyperthreading). Does nothing on processors without hardware threading support. Use this in tight loops where you're waiting for memory operations or when you want to be more cooperative with hardware threads on the same core without giving up the time slice to other processes.
|
static |
Suspends execution of the current thread and yields the remaining time slice to other threads.
This allows other threads or processes to run. Use this in spin-wait loops or when the current thread is waiting for work from other threads. On most platforms this translates to a scheduler yield. Prefer this over YieldHardwareThread() for general cooperative multitasking scenarios.