#include <nitro/os.h>
void OS_CreateThread(
OSThread* thread ,
void (*func)(void*) ,
void* arg ,
void* stack,
u32 stackSize ,
u32 prio );
thread | Points to the thread structure to be initialized |
func | Points to the function that starts execution |
arg | The argument to pass to the function that begins execution |
stack | The starting address of the stack pointer. Items are put into the stack from the top, so the highest address of the stack must be specified. The address assigned must have a 4-byte alignment. |
stackSize | Stack size (in bytes). Must be a multiple of 4. |
prio | Thread priority. 0 is the highest priority and 31 is the lowest. A thread called with OSInitThread will have a priority of 16 .When threads are created with the same priority, the latest one created will have priority. |
None.
Creates threads.
thread is a pointer to the thread structure to be created. The thread is executed from func. The value assigned to arg is used as the first argument to func.
The stack memory is specified by stack and stackSize. stack represents the start address of the stack pointer and has a value of the highest address in the stack memory +1. (Actually, four bytes are already allocated as a check code for the stack when a thread is created.)
The threads created by OS_CreateThread()
go immediately into sleep mode, so they need to be explicitly reactivated with OS_WakeupThreadDirect()
.
Example:
#define THREAD_PRIO 10 #define STACK_SIZE 1024 void proc( void* arg ); OSThread thread; u64 stack[ STACK_SIZE / sizeof(u64) ]; void nitroMain() { : OS_InitThread(); OS_CreateThread( &thread, proc, NULL, stack+STACK_SIZE/sizeof(u64), STACK_SIZE,THREAD_PRIO ); OS_WakeupThreadDirect( &thread ); : } void proc( void *arg ) { : }
OS_InitThread
OS_SleepThread
OS_WakeupThread
OS_WakeupThreadDirect
OS_ExitThread
OS_DestroyThread
2005/07/08 Deleted limitaton on the number of threads.
2004/11/01 Added description of change to number of threads.
2004/04/27 Added description of idle thread.
2004/02/26 arg added. Description of thread priority 0-31 added.
2003/01/12 Initial version.
CONFIDENTIAL