Defined in include/foundation/PxThread.h

class PxThreadImpl

Public Types

typedef size_t Id
typedef void *(*ExecuteFn)(void*)

Public Functions


Construct (but do not start) the thread object.

The OS thread object will not be created until start() is called. Executes in the context of the spawning thread.

PxThreadImpl(ExecuteFn fn, void *arg, const char *name)

Construct and start the the thread, passing the given arg to the given fn.

(pthread style)


Deallocate all resources associated with the thread.

Should be called in the context of the spawning thread.

void start(PxU32 stackSize, PxRunnable *r)

Create the OS thread and start it running.

Called in the context of the spawning thread. If an affinity mask has previously been set then it will be applied after the thread has been created.

void kill()

Violently kill the current thread.

Blunt instrument, not recommended since it can leave all kinds of things unreleased (stack, memory, mutexes…) Should be called in the context of the spawning thread.

void signalQuit()

Stop the thread.

Signals the spawned thread that it should stop, so the thread should check regularly

bool waitForQuit()

Wait for a thread to stop.

Should be called in the context of the spawning thread. Returns false if the thread has not been started.

bool quitIsSignalled()

check whether the thread is signalled to quit.

Called in the context of the spawned thread.

void quit()

Cleanly shut down this thread.

Called in the context of the spawned thread.

PxU32 setAffinityMask(PxU32 mask)

Change the affinity mask for this thread.

The mask is a platform specific value.

On Windows, Linux, and Switch platforms, each set mask bit represents the index of a logical processor that the OS may schedule thread execution on. Bits outside the range of valid logical processors may be ignored or cause the function to return an error.

On Apple platforms, this function has no effect.

If the thread has not yet been started then the mask is stored and applied when the thread is started.

If the thread has already been started then this method returns the previous affinity mask on success, otherwise it returns zero.

void setPriority(PxThreadPriority::Enum prio)

Set thread priority.

void setName(const char *name)

set the thread’s name

Public Static Functions

static PxU32 getDefaultStackSize()
static Id getId()
static PxThreadPriority::Enum getPriority(Id threadId)
static void sleep(PxU32 ms)

Put the current thread to sleep for the given number of milliseconds.

static void yield()

Yield the current thread’s slot on the CPU.

static void yieldProcessor()

Inform the processor that we’re in a busy wait to give it a chance to do something clever.

yield() yields the thread, while yieldProcessor() aims to yield the processor

static PxU32 getNbPhysicalCores()

Return the number of physical cores (does not include hyper-threaded cores), returns 0 on failure.

static PxU32 getSize()

Size of this class.