ezEngine Release 26.3
Loading...
Searching...
No Matches
ezThread Class Referenceabstract

This class is the base class for platform independent long running threads. More...

#include <Thread.h>

Inheritance diagram for ezThread:

Public Types

enum  ezThreadStatus { Created = 0 , Running , Finished }
 Thread execution state. More...
 

Public Member Functions

 ezThread (ezStringView sName="ezThread", ezUInt32 uiStackSize=128 *1024)
 Creates a new thread with specified name and stack size.
 
virtual ~ezThread ()
 Destructor checks if the thread is deleted while still running, which is not allowed as this is a data hazard.
 
ezThreadStatus GetThreadStatus () const
 Returns the thread status.
 
bool IsRunning () const
 Helper function to determine if the thread is running.
 
const char * GetThreadName () const
 Returns the thread name.
 
- Public Member Functions inherited from ezOSThread
 ezOSThread (ezOSThreadEntryPoint threadEntryPoint, void *pUserData=nullptr, ezStringView sName="ezOSThread", ezUInt32 uiStackSize=128 *1024)
 Initializes the thread instance (e.g. thread creation etc.)
 
virtual ~ezOSThread ()
 Destructor.
 
void Start ()
 Starts the thread.
 
void Join ()
 Waits in the calling thread until the thread has finished execution (e.g. returned from the thread function)
 
const ezThreadID & GetThreadID () const
 Returns the thread ID of the thread object, may be used in comparison operations with ezThreadUtils::GetCurrentThreadID() for example.
 

Static Public Member Functions

static const ezThreadGetCurrentThread ()
 Returns the current ezThread if the current platform thread is an ezThread. Returns nullptr otherwise.
 
- Static Public Member Functions inherited from ezOSThread
static ezInt32 GetThreadCount ()
 Returns how many ezOSThreads are currently active.
 

Static Public Attributes

static ezEvent< const ezThreadEvent &, ezMutexs_ThreadEvents
 Global events for thread lifecycle monitoring.
 

Private Member Functions

virtual ezUInt32 Run ()=0
 Pure virtual function that contains the thread's main execution logic.
 

Friends

ezUInt32 RunThread (ezThread *pThread)
 

Additional Inherited Members

- Protected Attributes inherited from ezOSThread
ezThreadHandle m_hHandle
 
ezThreadID m_ThreadID
 
ezOSThreadEntryPoint m_EntryPoint
 
void * m_pUserData
 
ezString m_sName
 
ezUInt32 m_uiStackSize
 

Detailed Description

This class is the base class for platform independent long running threads.

Used by deriving from this class and overriding the Run() method.

Member Enumeration Documentation

◆ ezThreadStatus

Thread execution state.

Enumerator
Created 

Thread created but not yet started.

Running 

Thread is currently executing.

Finished 

Thread execution has completed.

Constructor & Destructor Documentation

◆ ezThread()

ezThread::ezThread ( ezStringView  sName = "ezThread",
ezUInt32  uiStackSize = 128 * 1024 
)

Creates a new thread with specified name and stack size.

The thread is created in Created state and must be started separately. Default stack size of 128KB is suitable for most purposes.

Member Function Documentation

◆ Run()

virtual ezUInt32 ezThread::Run ( )
privatepure virtual

Pure virtual function that contains the thread's main execution logic.

Override this method to implement the work that the thread should perform. The return value is passed as the thread exit code and can be retrieved after the thread finishes.

Implemented in ezRemoteThread, ezAssetProcessorThread, ezTaskWorkerThread, and ezThreadWithDispatcher.

Member Data Documentation

◆ s_ThreadEvents

ezEvent< const ezThreadEvent &, ezMutex > ezThread::s_ThreadEvents
static

Global events for thread lifecycle monitoring.

These events inform about threads starting and finishing. Events are raised on the executing thread, allowing thread-specific initialization and cleanup code to be executed during callbacks. Useful for setting up thread-local storage or registering threads with profiling systems.


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