Thread

Engine/source/platform/threads/thread.h

More...

Public Types

Parent 

Protected Attributes

Used to signal threads need to stop.

Public Attributes

bool

If set, the thread will delete itself once it has finished running.

Protected Functions

_setName(const char * name)

Set the name of this thread for identification in debuggers.

Public Functions

Thread(ThreadRunFunction func, void * arg, bool start_thread, bool autodelete)

Create a thread.

Destroy a thread.

bool

Threads may call checkForStop() periodically to check if they've been asked to stop.

Returns the platform specific thread id for this thread.

bool

Returns true if the thread is running.

bool
join()

Block until the thread stops running.

run(void * arg)

Run the Thread's entry point function.

start(void * arg)

Start a thread.

stop()

Ask a thread to stop running.

Detailed Description

Public Types

typedef void Parent 

Protected Attributes

PlatformThreadData * mData 
U32 shouldStop 

Used to signal threads need to stop.

Threads set this flag to false in start()

Public Attributes

bool autoDelete 

If set, the thread will delete itself once it has finished running.

Protected Functions

_setName(const char * name)

Set the name of this thread for identification in debuggers.

Maybe a NOP on platforms that do not support this. Always a NOP in non-debug builds.

Public Functions

Thread(ThreadRunFunction func, void * arg, bool start_thread, bool autodelete)

Create a thread.

Parameters:

func

The starting function for the thread.

arg

Data to be passed to func, when the thread starts.

start_thread

Supported for compatibility. Must be false. Starting threads from within the constructor is not allowed anymore as the run() method is virtual.

~Thread()

Destroy a thread.

The thread MUST be allowed to exit before it is destroyed.

checkForStop()

Threads may call checkForStop() periodically to check if they've been asked to stop.

As soon as checkForStop() returns true, the thread should clean up and return.

getId()

Returns the platform specific thread id for this thread.

isAlive()

Returns true if the thread is running.

join()

Block until the thread stops running.

note:

Don't use this in combination with auto-deletion as otherwise the thread will kill itself while still executing the join() method on the waiting thread.

run(void * arg)

Run the Thread's entry point function.

Override this method in a subclass of Thread to create threaded code in an object oriented way, and without passing a function ptr to Thread(). Also, you can call this method directly to execute the thread's code in a non-threaded way.

Reimplemented by: AsyncUpdateThread, ThreadPool::WorkerThread, ExecuteThread

start(void * arg)

Start a thread.

Sets shouldStop to false and calls run() in a new thread of execution.

stop()

Ask a thread to stop running.