Overview
The thread API provides functions for creating and managing PPU threads, along with synchronization primitives like mutexes and condition variables.Thread Management
sysThreadCreate
Create a new PPU thread.Pointer to storage for the thread ID
Thread entry point function
Argument passed to entry function
Thread priority (0 = highest, higher values = lower priority)
Stack size in bytes
Thread flags:
THREAD_JOINABLE (1) or 0Thread name for debugging
Zero on success, error code otherwise
sysThreadJoin
Wait for a joinable thread to terminate.Thread ID returned by sysThreadCreate
Pointer to storage for thread return value
Zero on success, error code otherwise
sysThreadExit
Terminate the current thread.Return value for sysThreadJoin
sysThreadYield
Voluntarily yield the CPU to another thread.Zero on success, error code otherwise
sysThreadDetach
Make a thread non-joinable (detached).Thread ID to detach
Zero on success, error code otherwise
sysThreadGetId
Get the current thread’s ID.Pointer to storage for current thread ID
Zero on success, error code otherwise
sysThreadSetPriority
Change thread priority.Thread ID
New priority value
Zero on success, error code otherwise
sysThreadGetPriority
Get thread priority.Thread ID
Pointer to storage for priority value
Zero on success, error code otherwise
Mutex
sysMutexCreate
Create a mutex for mutual exclusion.Pointer to storage for mutex ID
Pointer to mutex attributes
Zero on success, error code otherwise
sysMutexDestroy
Destroy a mutex.Mutex ID
Zero on success, error code otherwise
sysMutexLock
Lock a mutex (blocking).Mutex ID
Timeout in microseconds, or 0 for no timeout
Zero on success, error code on timeout or error
sysMutexTryLock
Attempt to lock a mutex without blocking.Mutex ID
Zero if locked successfully, nonzero if already locked or error
sysMutexUnlock
Unlock a previously locked mutex.Mutex ID
Zero on success, error code otherwise
Condition Variables
sysCondCreate
Create a condition variable.Pointer to storage for condition variable ID
Associated mutex ID
Pointer to condition variable attributes
Zero on success, error code otherwise
sysCondDestroy
Destroy a condition variable.Condition variable ID
Zero on success, error code otherwise
sysCondWait
Wait for a condition variable to be signaled.Condition variable ID
Timeout in microseconds, or 0 for no timeout
Zero on success, error code on timeout or error
sysCondSignal
Signal one waiting thread.Condition variable ID
Zero on success, error code otherwise
sysCondBroadcast
Signal all waiting threads.Condition variable ID
Zero on success, error code otherwise
Constants
Thread Flags
THREAD_JOINABLE(1) - Thread can be joinedTHREAD_INTERRUPT(2) - Thread triggered by interrupt
Mutex Protocols
SYS_MUTEX_PROTOCOL_FIFO(1) - FIFO schedulingSYS_MUTEX_PROTOCOL_PRIO(2) - Priority-based schedulingSYS_MUTEX_PROTOCOL_PRIO_INHERIT(3) - Priority inheritance
Mutex Attributes
SYS_MUTEX_ATTR_RECURSIVE(0x0010) - Allow recursive lockingSYS_MUTEX_ATTR_NOT_RECURSIVE(0x0020) - Disallow recursive lockingSYS_MUTEX_ATTR_ADAPTIVE(0x1000) - Adaptive mutexSYS_MUTEX_ATTR_NOT_ADAPTIVE(0x2000) - Non-adaptive mutex