1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<HTML>
3<HEAD>
4<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
5<META name="GENERATOR" content="IBM WebSphere Studio Homepage Builder Version 7.0.0.0 for Windows">
6<META http-equiv="Content-Style-Type" content="text/css">
7<TITLE>OS_CreateThread</TITLE>
8<LINK rel="stylesheet" href="../../css/nitro.css" type="text/css">
9</HEAD>
10<BODY>
11<H1 align="left">OS_CreateThread <IMG src="../../image/NTR.gif" align="middle"><IMG src="../../image/TWL.gif" align="middle"></H1>
12<H2>Syntax</H2>
13<DL>
14  <DD>
15<PRE><CODE>#include &lt;nitro/os.h&gt;</CODE></PRE>
16  <PRE><CODE>void OS_CreateThread(
17     OSThread*  thread ,
18     void       (*func)(void*) ,
19     void*      arg ,
20     void*       stack,
21     u32        stackSize ,
22     u32         prio );
23  </CODE></PRE>
24</DL>
25<H2>Arguments</H2>
26<TABLE border="1" width="100%">
27  <TBODY>
28    <TR>
29<TD width="13%"><EM><STRONG>thread</STRONG></EM></TD>
30<TD width="87%">Points to the thread structure to be initialized</TD>
31    </TR>
32    <TR>
33<TD width="13%"><EM><STRONG>func</STRONG></EM></TD>
34<TD width="87%">Points to the function that starts execution</TD>
35    </TR>
36    <TR>
37<TD width="13%"><EM><STRONG>arg</STRONG></EM></TD>
38<TD width="87%">The argument to pass to the function that begins execution</TD>
39    </TR>
40    <TR>
41<TD><EM><STRONG>stack</STRONG></EM></TD>
42<TD>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.</TD>
43    </TR>
44    <TR>
45<TD><EM><STRONG>stackSize</STRONG></EM></TD>
46<TD>Stack size (in bytes). &nbsp;Must be a multiple of 4.</TD>
47    </TR>
48    <TR>
49<TD><EM><STRONG>prio</STRONG></EM></TD>
50<TD>Thread priority. 0 is the highest priority and 31 is the lowest. A thread called with <code>OSInitThread</code> will have a priority of <code>16</code>.<br />When threads are created with the same priority, the latest one created will have priority.</TD>
51    </TR>
52  </TBODY>
53</TABLE>
54<H2>Return Values</H2>
55<P>None.</P>
56<H2>Description</H2>
57<P>Creates threads.</P>
58<P><EM><B>thread</B></EM> is a pointer to the thread structure to be created. The thread is executed from <EM><B>func</B></EM>. The value assigned to <EM><B>arg</B></EM> is used as the first argument to <EM><B>func</B></EM>.</P>
59<P>The stack memory is specified by <EM><B>stack</B></EM> and <B><EM>stackSize</EM></B>. <EM><B>stack</B></EM> 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.)</P>
60<P>The threads created by <code>OS_CreateThread()</code> go immediately into sleep mode, so they need to be explicitly reactivated with <a href="OS_WakeupThreadDirect.html"><code>OS_WakeupThreadDirect()</code></a>.</P>
61
62<BLOCKQUOTE>Example:<BR>
63<PRE>#define THREAD_PRIO 10
64#define STACK_SIZE 1024
65
66void proc( void* arg );
67OSThread thread;
68u64 stack[ STACK_SIZE / sizeof(u64) ];
69
70void nitroMain()
71{
72	:
73  OS_InitThread();
74  <FONT color="#ff0000">OS_CreateThread( &amp;thread, proc, NULL,
75			stack+STACK_SIZE/sizeof(u64), STACK_SIZE,THREAD_PRIO );</FONT>
76  OS_WakeupThreadDirect( &amp;thread );
77	:
78}
79
80void proc( void *arg )
81{
82	:
83}</PRE>
84</BLOCKQUOTE>
85
86<H2>See Also</H2>
87<P><CODE><A href="OS_InitThread.html">OS_InitThread</A><BR>
88<A href="OS_SleepThread.html">OS_SleepThread</A><BR>
89<A href="OS_WakeupThread.html">OS_WakeupThread</A><BR>
90<A href="OS_WakeupThreadDirect.html">OS_WakeupThreadDirect</A></CODE><BR>
91<CODE><A href="OS_ExitThread.html">OS_ExitThread</A><BR>
92<A href="OS_DestroyThread.html">OS_DestroyThread</A><BR></CODE></P>
93<H2>Revision History</H2>
94<P>2005/07/08 Deleted limitaton on the number of threads.<BR>2004/11/01 Added description of change to number of threads.<BR>2004/04/27 Added description of idle thread.<BR>2004/02/26 arg added. Description of thread priority 0-31 added.<BR>2003/01/12 Initial version.</P>
95<hr><p>CONFIDENTIAL</p></body>
96</HTML>
97