OS_CreateThread

C Specification

#include <nitro/os.h>
void OS_CreateThread(   OSThread*   thread,
			void        (*func)(void*),
			void*       arg,
			void*       stack,
			u32         stackSize,
			u32         prio );  

Arguments

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 down, so be aware that the highest position of the stack must be specified. The address must be given a 4-byte alignment.
stackSize Stack size (in bytes).  Must be in multiples 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.

Return Values

None.

Description

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 )
{

}

See Also

OS_InitThread, OS_SleepThread, OS_WakeupThread, OS_WakeupThreadDirect
OS_ExitThread, OS_DestroyThread

Revision History

07/08/2005 Deleted limitaton on the number of threads.
11/01/2004 Added description of change to number of threads.
04/27/2004 Added description of idle thread.
02/26/2004 arg added. Description of thread priority 0-31 added.
01/12/2003 Initial version.