N64® Functions Menu

al - Audio Library Functions
gDP - DP GBI Macros
gdSP - General GBI Macros
gSP - SP GBI Macros
gt - Turbo Microcode RDP
gu - Graphics Utilities
Math - Math Functions
nuSys - NuSystem
os - N64 Operating System
sp - Sprite Library Functions
uh - Host to Target IO
64DD - N64 Disk Drive

Nintendo® Confidential

## osCreateThread
osDestroyThread

Syntax
#include <ultra64.h>
void osCreateThread(OSThread *t, OSId id, void (*entry)(void *), void *arg, void *sp, OSPri pri);
void osDestroyThread(OSThread *t));
Explanation
The osCreateThread and osDestroyThread functions register and unregister a schedulable object.
Threads are the basic schedulable unit of the Nintendo 64 operating system. The OSThread data structure stores the context of the thread and acts as a handle by which the thread may be referenced by thread manipulation routines.
The osCreateThread routine initializes the given thread pointed to by the t argument and puts the thread on an active queue so that it becomes known to the Nintendo 64 debugger (gvd). Threads are initialized in the stopped state. The thread will eventually be placed on the run queue by calling the osStartThread routine.
The id argument is assigned to the thread by the application and is used solely by the debugger user interface to provide a more convenient handle to the thread than the thread structure address.
The procedure specified by the entry argument is jumped to when the thread is started, and this procedure is passed the single argument specified by the arg argument.
Similarly, the stack is initialized to the location pointed to by the sp argument. Note that stacks grow backwards (towards smaller addresses) with the MIPS compiler tools. The memory region assigned to the stack must be of least size OS_MIN_STACKSIZE in bytes. The maximum size of the stack must be the sum of the stack frame sizes of its maximum procedure call depth plus 16. Stacks must also be 64-bit aligned, so they should be declared as 'long long int' and type-casted when passed to this function. Use the stacktool program to help compute stack sizes.
The pri argument specifies a nondegradable priority value that must range from OS_PRIORITY_IDLE (0) to OS_PRIORITY_APPMAX (127). In addition, to enable all interrupts, this routine also specifies the floating point control/status register to (1) flush denormalized numbers to zero and to (2) signal invalid operation exception to catch generation of Not a Numbers (NaNs). For more information, refer to the Floating-Point Operations and Exceptions sections in the R4300 User's Manual.
The osDestroyThread routine removes the given thread pointed to by the t argument from the active queue as well as any other queue the thread may be on. More specifically, after you call osDestroyThread if the thread was on the run queue, it is no longer runnable. If the thread was blocked on a message queue, it can no longer send or receive a message. If the argument is NULL, the dispatcher is called and the invoking (running) thread is not returned to the run queue. Unexpected results will occur if a destroyed thread is ever placed back on the run queue.
See Also
osGetThreadId
osGetThreadPri
osStartThread
osStopThread
osYieldThread

Nintendo® Confidential Warning: all information in this document is confidential and covered by a non-disclosure agreement. You are responsible for keeping this information confidential and protected. Nintendo will vigorously enforce this responsibility.
Copyright © 1998
Nintendo of America Inc. All rights reserved
Nintendo and N64 are registered trademarks of Nintendo
Last updated March 1998