<p>A thread is an abstraction of an independent instructions flow. In ChibiOS/RT a thread is represented by a "C" function owning a processor context, state informations and a dedicated stack area. In this scenario static variables are shared among all threads while automatic variables are local to the thread.<br/>
Operations defined for threads:</p>
<ul>
<li><b>Init</b>, a thread is prepared and put in the suspended state.</li>
<li><b>Create</b>, a thread is started on the specified thread function. This operation is available in multiple variants, both static and dynamic.</li>
<li><b>Exit</b>, a thread terminates by returning from its top level function or invoking a specific API, the thread can return a value that can be retrieved by other threads.</li>
<li><b>Wait</b>, a thread waits for the termination of another thread and retrieves its return value.</li>
<li><b>Resume</b>, a thread created in suspended state is started.</li>
<li><b>Sleep</b>, the execution of a thread is suspended for the specified amount of time or the specified future absolute time is reached.</li>
<li><b>SetPriority</b>, a thread changes its own priority level.</li>
<li><b>Yield</b>, a thread voluntarily renounces to its time slot.</li>
</ul>
<p>The threads subsystem is implicitly included in kernel however some of its part may be excluded by disabling them in <code><aclass="el"href="chconf_8h.html"title="Configuration file template.">chconf.h</a></code>, see the <code>CH_USE_WAITEXIT</code> and <code>CH_USE_DYNAMIC</code> configuration options. </p>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Structure representing a thread. <ahref="struct_thread.html#_details">More...</a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight"><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: Ready to run, waiting on the ready list. <ahref="#ga1f7b83c73a5b850a3f33bddbdb024fb3"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight"><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: Currently running. <ahref="#ga247c4d33e862f51e90df9a602175f80b"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight"><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: <aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> created in suspended state. <ahref="#gace00089d9d68ba83bb866396332c15d8"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight"><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: Waiting on a semaphore. <ahref="#gad0b81cae859c0a6bc6a0d2036aa8e272"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight"><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: Waiting on a mutex. <ahref="#gac18de5096ff3c841e69672cab0868cdf"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight"><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: Waiting in <code><aclass="el"href="group__condvars.html#ga466f912bc9b09b133fae862993004ffe"title="Waits on the condition variable releasing the mutex lock.">chCondWait()</a></code>. <ahref="#ga286c5b1a6459d654d5794fc17e93c939"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight"><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: Waiting in <code><aclass="el"href="group__threads.html#ga8b10a49e2ec522a5ddecabdc453afcab"title="Suspends the invoking thread for the specified time.">chThdSleep()</a></code> or <code><aclass="el"href="group__threads.html#ga9e6e2f8d46d415e8f0862daf0be1d984"title="Suspends the invoking thread until the system time arrives to the specified value.">chThdSleepUntil()</a></code>. <ahref="#ga1b56c4f78480669018aea61711430048"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight"><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: Waiting in <code><aclass="el"href="group__threads.html#ga94a5727ecdbe0f738dfc8e1ede1c3409"title="Blocks the execution of the invoking thread until the specified thread terminates then the exit code ...">chThdWait()</a></code>. <ahref="#gaf726245829b74db3a77a5f4bcc17bf67"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight"><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: Waiting in <code>chEvtWaitXXX()</code>. <ahref="#gacd5f28475be26c300aa3444b9bad8feb"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight"><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: Waiting in <code><aclass="el"href="group__events.html#ga90d702300eecee3d05f83e95b155c3ee"title="Waits for all the specified events.">chEvtWaitAllTimeout()</a></code>. <ahref="#ga1227eb701b7ecaa8e8cd03edeeb79a92"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight"><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: Waiting in <code><aclass="el"href="group__messages.html#ga29a48a438e97dc47cb798a84e13764cb"title="Sends a message to the specified thread.">chMsgSend()</a></code>. <ahref="#gaff813590802bfd53cbf0560b680b89f5"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight"><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: Waiting in <code><aclass="el"href="group__messages.html#gae68fefbf9d0404bbf56ae354961fae41"title="Suspends the thread and waits for an incoming message.">chMsgWait()</a></code>. <ahref="#gaf46c55b4468f0dad5cd0b3ef73e1be26"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight"><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: After termination. <ahref="#ga10583a3a3fb4c62693bb08796f8d13ae"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight"><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> memory mode: pool. <ahref="#ga70a7c2fa69d7ca90e6f191c2ebd8cc6f"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Returns a pointer to the current <code><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a></code>. <ahref="#gaa36662628234799d205ff8c0cc6745c5"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Returns the current thread priority. <ahref="#gac71903de6268d886ff58022854b8b6dd"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Returns the pointer to the <code><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a></code> local storage area, if any. <ahref="#ga44ea29c71507ec19cf668de199fcbcca"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Verifies if the specified thread is in the <code>THD_STATE_FINAL</code> state. <ahref="#ga91fad809cfc40e5e989b5bc893741f30"></a><br/></td></tr>
<tr><tdclass="memItemLeft"align="right"valign="top">#define </td><tdclass="memItemRight"valign="bottom"><aclass="el"href="group__threads.html#ga5591a9f97ff77b40bd5fc29f16f12a6b">chThdShouldTerminate</a>() (currp->p_flags & THD_TERMINATE)</td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Verifies if the current thread has a termination request pending. <ahref="#ga5591a9f97ff77b40bd5fc29f16f12a6b"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Resumes a thread created with <code>chThdInit()</code>. <ahref="#gaca27314f95f0b691d5a83a017157fd09"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Suspends the invoking thread for the specified time. <ahref="#ga851dc0c4ac72885bf09feebdef4673ac"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Delays the invoking thread for the specified number of seconds. <ahref="#ga5fc3d014124e558bc59c423a74668c8d"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Delays the invoking thread for the specified number of milliseconds. <ahref="#ga5aebc25e053a0094714abce4cad9f56f"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Delays the invoking thread for the specified number of microseconds. <ahref="#ga596f4015871a919694911bc50ba8bd94"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Initializes a thread structure. <ahref="#ga4f6ae58bb3cedfc03aacde6d49e49d35"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Creates a new thread into a static memory area. <ahref="#gac6de13d4044b32d3ae9e2066b5d4c030"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Creates a new thread into a static memory area. <ahref="#ga048e588238dd336c6059133b3d0c3435"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Creates a new thread allocating the memory from the heap. <ahref="#ga50b84e3e82a4e09c1066e1d422e4c780"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Creates a new thread allocating the memory from the specified memory pool. <ahref="#gad3ccc1a6f054c543258ed2fe97ed2f58"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Changes the running thread priority level then reschedules if necessary. <ahref="#ga5a5d9388c64e4c1a3aec129d2831eefe"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Requests a thread termination. <ahref="#ga7ea7371fa41598ebd523622587ce3f22"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Suspends the invoking thread for the specified time. <ahref="#ga8b10a49e2ec522a5ddecabdc453afcab"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Suspends the invoking thread until the system time arrives to the specified value. <ahref="#ga9e6e2f8d46d415e8f0862daf0be1d984"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Terminates the current thread by specifying an exit status code. <ahref="#ga24ab3a3a4d70214ee360867a1c3c75ac"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Adds a reference to a thread object. <ahref="#gabefc5734beaf29ae0bcd52cd41744930"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Releases a reference to a thread object. <ahref="#gaa22f80040cf192015be4607f31a0ac80"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Blocks the execution of the invoking thread until the specified thread terminates then the exit code is returned. <ahref="#ga94a5727ecdbe0f738dfc8e1ede1c3409"></a><br/></td></tr>
<p><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: Ready to run, waiting on the ready list. </p>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00175">175</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: Currently running. </p>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00177">177</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: <aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> created in suspended state. </p>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00179">179</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: Waiting on a semaphore. </p>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00181">181</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p>Referenced by <aclass="el"href="group__mutexes.html#ga2d6350c2d147d1165c359f30798205f5">chMtxLockS()</a>, <aclass="el"href="group__semaphores.html#ga0dc7b4339506de346d67b4560b271e44">chSemSignalWait()</a>, <aclass="el"href="group__semaphores.html#gaa2c0367078533e291d2e889e251d8b67">chSemWaitS()</a>, and <aclass="el"href="group__semaphores.html#ga924ec5d191bb8debe8727ae4dd5d6d03">chSemWaitTimeoutS()</a>.</p>
<p><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: Waiting on a mutex. </p>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00183">183</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p>Referenced by <aclass="el"href="group__mutexes.html#ga2d6350c2d147d1165c359f30798205f5">chMtxLockS()</a>.</p>
<p><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: Waiting in <code><aclass="el"href="group__condvars.html#ga466f912bc9b09b133fae862993004ffe"title="Waits on the condition variable releasing the mutex lock.">chCondWait()</a></code>. </p>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00185">185</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p>Referenced by <aclass="el"href="group__condvars.html#gab6357d80b01ed8d225ef1e30a66248f9">chCondWaitS()</a>, <aclass="el"href="group__condvars.html#ga9cf6ebe4c9f28cb206fab14984a18d29">chCondWaitTimeoutS()</a>, and <aclass="el"href="group__mutexes.html#ga2d6350c2d147d1165c359f30798205f5">chMtxLockS()</a>.</p>
<p><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: Waiting in <code><aclass="el"href="group__threads.html#ga8b10a49e2ec522a5ddecabdc453afcab"title="Suspends the invoking thread for the specified time.">chThdSleep()</a></code> or <code><aclass="el"href="group__threads.html#ga9e6e2f8d46d415e8f0862daf0be1d984"title="Suspends the invoking thread until the system time arrives to the specified value.">chThdSleepUntil()</a></code>. </p>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00187">187</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: Waiting in <code><aclass="el"href="group__threads.html#ga94a5727ecdbe0f738dfc8e1ede1c3409"title="Blocks the execution of the invoking thread until the specified thread terminates then the exit code ...">chThdWait()</a></code>. </p>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00189">189</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p>Referenced by <aclass="el"href="group__threads.html#ga94a5727ecdbe0f738dfc8e1ede1c3409">chThdWait()</a>.</p>
<p><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: Waiting in <code>chEvtWaitXXX()</code>. </p>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00191">191</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p>Referenced by <aclass="el"href="group__events.html#ga6c219038c3e618e2142c6e1601997907">chEvtSignalI()</a>, <aclass="el"href="group__events.html#gabd731d3ed2f037b2409e370676575f8d">chEvtWaitAny()</a>, <aclass="el"href="group__events.html#gaf690406ccc833e2c9235e7e2041a6715">chEvtWaitAnyTimeout()</a>, <aclass="el"href="group__events.html#ga77651e22578713ebe355c1213286c2e9">chEvtWaitOne()</a>, and <aclass="el"href="group__events.html#ga2944a7fc82e7cc15537f5a7c04f457d3">chEvtWaitOneTimeout()</a>.</p>
<p><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: Waiting in <code><aclass="el"href="group__events.html#ga90d702300eecee3d05f83e95b155c3ee"title="Waits for all the specified events.">chEvtWaitAllTimeout()</a></code>. </p>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00193">193</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p>Referenced by <aclass="el"href="group__events.html#ga6c219038c3e618e2142c6e1601997907">chEvtSignalI()</a>, <aclass="el"href="group__events.html#ga8c5c6bf310a08cdc836d23f98a87dbf5">chEvtWaitAll()</a>, and <aclass="el"href="group__events.html#ga90d702300eecee3d05f83e95b155c3ee">chEvtWaitAllTimeout()</a>.</p>
<p><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: Waiting in <code><aclass="el"href="group__messages.html#ga29a48a438e97dc47cb798a84e13764cb"title="Sends a message to the specified thread.">chMsgSend()</a></code>. </p>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00195">195</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p>Referenced by <aclass="el"href="group__messages.html#ga29a48a438e97dc47cb798a84e13764cb">chMsgSend()</a>, and <aclass="el"href="group__mutexes.html#ga2d6350c2d147d1165c359f30798205f5">chMtxLockS()</a>.</p>
<p><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: Waiting in <code><aclass="el"href="group__messages.html#gae68fefbf9d0404bbf56ae354961fae41"title="Suspends the thread and waits for an incoming message.">chMsgWait()</a></code>. </p>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00197">197</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p>Referenced by <aclass="el"href="group__messages.html#ga29a48a438e97dc47cb798a84e13764cb">chMsgSend()</a>, and <aclass="el"href="group__messages.html#gae68fefbf9d0404bbf56ae354961fae41">chMsgWait()</a>.</p>
<p><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> state: After termination. </p>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00199">199</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p>Referenced by <aclass="el"href="group__threads.html#ga24ab3a3a4d70214ee360867a1c3c75ac">chThdExit()</a>, <aclass="el"href="group__threads.html#gaa22f80040cf192015be4607f31a0ac80">chThdRelease()</a>, and <aclass="el"href="group__threads.html#ga94a5727ecdbe0f738dfc8e1ede1c3409">chThdWait()</a>.</p>
<p><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> memory mode mask. </p>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00204">204</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p>Referenced by <aclass="el"href="group__threads.html#ga24ab3a3a4d70214ee360867a1c3c75ac">chThdExit()</a>, and <aclass="el"href="group__threads.html#gaa22f80040cf192015be4607f31a0ac80">chThdRelease()</a>.</p>
<p><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> memory mode: static. </p>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00205">205</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> memory mode: heap. </p>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00206">206</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> memory mode: pool. </p>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00207">207</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00208">208</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p>Returns a pointer to the current <code><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a></code>. </p>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00253">253</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00258">258</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p>Returns the pointer to the <code><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a></code> local storage area, if any. </p>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00263">263</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<tr><tdvalign="top"></td><tdvalign="top"><em>FALSE</em> </td><td>thread not terminated. </td></tr>
</table>
</dd>
</dl>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00272">272</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<tr><tdvalign="top"></td><tdvalign="top"><em>FALSE</em> </td><td>termination request not pended. </td></tr>
</table>
</dd>
</dl>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00280">280</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>tp</em> </td><td>the pointer to the thread </td></tr>
</table>
</dd>
</dl>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00287">287</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p>Suspends the invoking thread for the specified time. </p>
<dl><dt><b>Parameters:</b></dt><dd>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>time</em> </td><td>the delay in system ticks, the special values are handled as follow:</p>
<ul>
<li><em>TIME_INFINITE</em> the thread enters an infinite sleep state.</li>
<li><em>TIME_IMMEDIATE</em> this value is accepted but interpreted as a normal time specification not as an immediate timeout specification.</li>
</ul>
</td></tr>
</table>
</dd>
</dl>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00301">301</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p>Referenced by <aclass="el"href="group___c_a_n.html#ga05d2448864b2cae4674ed7e6f3c576b8">canStart()</a>, <aclass="el"href="group__threads.html#ga8b10a49e2ec522a5ddecabdc453afcab">chThdSleep()</a>, and <aclass="el"href="group__threads.html#ga9e6e2f8d46d415e8f0862daf0be1d984">chThdSleepUntil()</a>.</p>
<p>Delays the invoking thread for the specified number of seconds. </p>
<dlclass="note"><dt><b>Note:</b></dt><dd>The specified time is rounded up to a value allowed by the real system clock. </dd>
<dd>
The maximum specified value is implementation dependent.</dd></dl>
<dl><dt><b>Parameters:</b></dt><dd>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>sec</em> </td><td>the time in seconds </td></tr>
</table>
</dd>
</dl>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00311">311</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p>Delays the invoking thread for the specified number of milliseconds. </p>
<dlclass="note"><dt><b>Note:</b></dt><dd>The specified time is rounded up to a value allowed by the real system clock. </dd>
<dd>
The maximum specified value is implementation dependent.</dd></dl>
<dl><dt><b>Parameters:</b></dt><dd>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>msec</em> </td><td>the time in milliseconds </td></tr>
</table>
</dd>
</dl>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00322">322</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p>Referenced by <aclass="el"href="group___m_m_c___s_p_i.html#ga9ff4f12fa759c3cb4aca2b64b11f1d22">mmcConnect()</a>.</p>
<p>Delays the invoking thread for the specified number of microseconds. </p>
<dlclass="note"><dt><b>Note:</b></dt><dd>The specified time is rounded up to a value allowed by the real system clock. </dd>
<dd>
The maximum specified value is implementation dependent.</dd></dl>
<dl><dt><b>Parameters:</b></dt><dd>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>usec</em> </td><td>the time in microseconds </td></tr>
</table>
</dd>
</dl>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00333">333</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<p><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a> function. </p>
<p>Definition at line <aclass="el"href="chthreads_8h_source.html#l00211">211</a> of file <aclass="el"href="chthreads_8h_source.html">chthreads.h</a>.</p>
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>tp</em> </td><td>pointer to the thread </td></tr>
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>prio</em> </td><td>the priority level for the new thread </td></tr>
</table>
</dd>
</dl>
<dlclass="return"><dt><b>Returns:</b></dt><dd>The same thread pointer passed as parameter. </dd></dl>
<p>Definition at line <aclass="el"href="chthreads_8c_source.html#l00074">74</a> of file <aclass="el"href="chthreads_8c_source.html">chthreads.c</a>.</p>
<p>Referenced by <aclass="el"href="group__system.html#gafe2c7de6567e98e487e009e81e3be10b">chSysInit()</a>, and <aclass="el"href="group__threads.html#gac6de13d4044b32d3ae9e2066b5d4c030">chThdCreateI()</a>.</p>
<p>The new thread is initialized but not inserted in the ready list, the initial state is <code>THD_STATE_SUSPENDED</code>. </p>
<dlclass="note"><dt><b>Note:</b></dt><dd>A thread can terminate by calling <code><aclass="el"href="group__threads.html#ga24ab3a3a4d70214ee360867a1c3c75ac"title="Terminates the current thread by specifying an exit status code.">chThdExit()</a></code> or by simply returning from its main function. </dd>
Threads created using this function do not obey to the <code>CH_DBG_FILL_THREADS</code> debug option because it would keep the kernel locked for too much time.</dd></dl>
<tr><tdvalign="top"><tt>[out]</tt> </td><tdvalign="top"><em>wsp</em> </td><td>pointer to a working area dedicated to the thread stack </td></tr>
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>size</em> </td><td>size of the working area </td></tr>
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>prio</em> </td><td>the priority level for the new thread </td></tr>
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>pf</em> </td><td>the thread function </td></tr>
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>arg</em> </td><td>an argument passed to the thread function. It can be <code>NULL</code>. </td></tr>
</table>
</dd>
</dl>
<dlclass="return"><dt><b>Returns:</b></dt><dd>The pointer to the <code><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a></code> structure allocated for the thread into the working space area. </dd></dl>
<p>Definition at line <aclass="el"href="chthreads_8c_source.html#l00137">137</a> of file <aclass="el"href="chthreads_8c_source.html">chthreads.c</a>.</p>
<p>Referenced by <aclass="el"href="group__threads.html#ga50b84e3e82a4e09c1066e1d422e4c780">chThdCreateFromHeap()</a>, <aclass="el"href="group__threads.html#gad3ccc1a6f054c543258ed2fe97ed2f58">chThdCreateFromMemoryPool()</a>, and <aclass="el"href="group__threads.html#ga048e588238dd336c6059133b3d0c3435">chThdCreateStatic()</a>.</p>
<areashape="rect"id="node3"href="group__threads.html#ga4f6ae58bb3cedfc03aacde6d49e49d35"title="Initializes a thread structure."alt=""coords="141,5,213,32"/></map>
<p>Creates a new thread into a static memory area. </p>
<dlclass="note"><dt><b>Note:</b></dt><dd>A thread can terminate by calling <code><aclass="el"href="group__threads.html#ga24ab3a3a4d70214ee360867a1c3c75ac"title="Terminates the current thread by specifying an exit status code.">chThdExit()</a></code> or by simply returning from its main function.</dd></dl>
<dl><dt><b>Parameters:</b></dt><dd>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"><tt>[out]</tt> </td><tdvalign="top"><em>wsp</em> </td><td>pointer to a working area dedicated to the thread stack </td></tr>
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>size</em> </td><td>size of the working area </td></tr>
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>prio</em> </td><td>the priority level for the new thread </td></tr>
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>pf</em> </td><td>the thread function </td></tr>
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>arg</em> </td><td>an argument passed to the thread function. It can be <code>NULL</code>. </td></tr>
</table>
</dd>
</dl>
<dlclass="return"><dt><b>Returns:</b></dt><dd>The pointer to the <code><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a></code> structure allocated for the thread into the working space area. </dd></dl>
<p>Definition at line <aclass="el"href="chthreads_8c_source.html#l00163">163</a> of file <aclass="el"href="chthreads_8c_source.html">chthreads.c</a>.</p>
<p>Referenced by <aclass="el"href="classchibios__rt_1_1_base_thread.html#a48012dd4151de3d40aa5139b230ed627">chibios_rt::BaseThread::BaseThread()</a>, and <aclass="el"href="group__system.html#gafe2c7de6567e98e487e009e81e3be10b">chSysInit()</a>.</p>
<areashape="rect"id="node3"href="group__scheduler.html#gae47a8819a21ef2d521124e76bfb37c95"title="Wakes up a thread."alt=""coords="165,56,264,83"/><areashape="rect"id="node9"href="group__threads.html#gac6de13d4044b32d3ae9e2066b5d4c030"title="Creates a new thread into a static memory area."alt=""coords="172,107,257,133"/><areashape="rect"id="node5"href="group__debug.html#gac7f8f0653faf2e3a93108ff5333821b7"title="Inserts in the circular debug trace buffer a context switch record."alt=""coords="316,5,396,32"/><areashape="rect"id="node7"href="group__scheduler.html#ga535d58cfb3436c8d4e4586c31c062298"title="Inserts a thread in the Ready List."alt=""coords="313,56,399,83"/><areashape="rect"id="node11"href="group__threads.html#ga4f6ae58bb3cedfc03aacde6d49e49d35"title="Initializes a thread structure."alt=""coords="320,107,392,133"/></map>
<p>Creates a new thread allocating the memory from the heap. </p>
<dlclass="note"><dt><b>Note:</b></dt><dd>A thread can terminate by calling <code><aclass="el"href="group__threads.html#ga24ab3a3a4d70214ee360867a1c3c75ac"title="Terminates the current thread by specifying an exit status code.">chThdExit()</a></code> or by simply returning from its main function. </dd>
The memory allocated for the thread is not released when the thread terminates but when a <code><aclass="el"href="group__threads.html#ga94a5727ecdbe0f738dfc8e1ede1c3409"title="Blocks the execution of the invoking thread until the specified thread terminates then the exit code ...">chThdWait()</a></code> is performed. </dd>
The function is available only if the <code>CH_USE_DYNAMIC</code>, <code>CH_USE_HEAP</code> and <code>CH_USE_WAITEXIT</code> options are enabled in <code><aclass="el"href="chconf_8h.html"title="Configuration file template.">chconf.h</a></code>.</dd></dl>
<dl><dt><b>Parameters:</b></dt><dd>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>heapp</em> </td><td>heap from which allocate the memory or <code>NULL</code> for the default heap </td></tr>
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>size</em> </td><td>size of the working area to be allocated </td></tr>
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>prio</em> </td><td>the priority level for the new thread </td></tr>
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>pf</em> </td><td>the thread function </td></tr>
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>arg</em> </td><td>an argument passed to the thread function. It can be <code>NULL</code>. </td></tr>
</table>
</dd>
</dl>
<dlclass="return"><dt><b>Returns:</b></dt><dd>The pointer to the <code><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a></code> structure allocated for the thread into the working space area. </dd></dl>
<dl><dt><b>Return values:</b></dt><dd>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"></td><tdvalign="top"><em>NULL</em> </td><td>if the memory cannot be allocated. </td></tr>
<p>Definition at line <aclass="el"href="chthreads_8c_source.html#l00200">200</a> of file <aclass="el"href="chthreads_8c_source.html">chthreads.c</a>.</p>
<areashape="rect"id="node3"href="group__heaps.html#ga3d364eec0bef8b1986f63b3288ebbd5f"title="Allocates a block of memory from the heap by using the first-fit algorithm."alt=""coords="195,5,277,32"/><areashape="rect"id="node5"href="group__scheduler.html#gae47a8819a21ef2d521124e76bfb37c95"title="Wakes up a thread."alt=""coords="187,56,285,83"/><areashape="rect"id="node11"href="group__threads.html#gac6de13d4044b32d3ae9e2066b5d4c030"title="Creates a new thread into a static memory area."alt=""coords="193,107,279,133"/><areashape="rect"id="node7"href="group__debug.html#gac7f8f0653faf2e3a93108ff5333821b7"title="Inserts in the circular debug trace buffer a context switch record."alt=""coords="337,5,417,32"/><areashape="rect"id="node9"href="group__scheduler.html#ga535d58cfb3436c8d4e4586c31c062298"title="Inserts a thread in the Ready List."alt=""coords="335,56,420,83"/><areashape="rect"id="node13"href="group__threads.html#ga4f6ae58bb3cedfc03aacde6d49e49d35"title="Initializes a thread structure."alt=""coords="341,107,413,133"/></map>
<dlclass="note"><dt><b>Note:</b></dt><dd>A thread can terminate by calling <code><aclass="el"href="group__threads.html#ga24ab3a3a4d70214ee360867a1c3c75ac"title="Terminates the current thread by specifying an exit status code.">chThdExit()</a></code> or by simply returning from its main function. </dd>
The memory allocated for the thread is not released when the thread terminates but when a <code><aclass="el"href="group__threads.html#ga94a5727ecdbe0f738dfc8e1ede1c3409"title="Blocks the execution of the invoking thread until the specified thread terminates then the exit code ...">chThdWait()</a></code> is performed. </dd>
The function is available only if the <code>CH_USE_DYNAMIC</code>, <code>CH_USE_MEMPOOLS</code> and <code>CH_USE_WAITEXIT</code> options are enabled in <code><aclass="el"href="chconf_8h.html"title="Configuration file template.">chconf.h</a></code>.</dd></dl>
<dl><dt><b>Parameters:</b></dt><dd>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>mp</em> </td><td>pointer to the memory pool object </td></tr>
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>prio</em> </td><td>the priority level for the new thread </td></tr>
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>pf</em> </td><td>the thread function </td></tr>
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>arg</em> </td><td>an argument passed to the thread function. It can be <code>NULL</code>. </td></tr>
</table>
</dd>
</dl>
<dlclass="return"><dt><b>Returns:</b></dt><dd>The pointer to the <code><aclass="el"href="struct_thread.html"title="Structure representing a thread.">Thread</a></code> structure allocated for the thread into the working space area. </dd></dl>
<dl><dt><b>Return values:</b></dt><dd>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"></td><tdvalign="top"><em>NULL</em> </td><td>if the memory pool is empty. </td></tr>
<p>Definition at line <aclass="el"href="chthreads_8c_source.html#l00245">245</a> of file <aclass="el"href="chthreads_8c_source.html">chthreads.c</a>.</p>
<areashape="rect"id="node3"href="group__pools.html#gab86190d70893fe708c75570af6720bd5"title="Allocates an object from a memory pool."alt=""coords="232,12,309,39"/><areashape="rect"id="node7"href="group__scheduler.html#gae47a8819a21ef2d521124e76bfb37c95"title="Wakes up a thread."alt=""coords="221,69,320,96"/><areashape="rect"id="node13"href="group__threads.html#gac6de13d4044b32d3ae9e2066b5d4c030"title="Creates a new thread into a static memory area."alt=""coords="228,132,313,159"/><areashape="rect"id="node5"href="group__pools.html#ga152fb3460d6b7426f0b6803bb38a0070"title="Allocates an object from a memory pool."alt=""coords="372,5,452,32"/><areashape="rect"id="node9"href="group__debug.html#gac7f8f0653faf2e3a93108ff5333821b7"title="Inserts in the circular debug trace buffer a context switch record."alt=""coords="372,56,452,83"/><areashape="rect"id="node11"href="group__scheduler.html#ga535d58cfb3436c8d4e4586c31c062298"title="Inserts a thread in the Ready List."alt=""coords="369,107,455,133"/><areashape="rect"id="node15"href="group__threads.html#ga4f6ae58bb3cedfc03aacde6d49e49d35"title="Initializes a thread structure."alt=""coords="376,157,448,184"/></map>
<p>Changes the running thread priority level then reschedules if necessary. </p>
<dlclass="note"><dt><b>Note:</b></dt><dd>The function returns the real thread priority regardless of the current priority that could be higher than the real priority because the priority inheritance mechanism.</dd></dl>
<dl><dt><b>Parameters:</b></dt><dd>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>newprio</em> </td><td>the new priority level of the running thread </td></tr>
</table>
</dd>
</dl>
<dlclass="return"><dt><b>Returns:</b></dt><dd>The old priority level. </dd></dl>
<p>Definition at line <aclass="el"href="chthreads_8c_source.html#l00282">282</a> of file <aclass="el"href="chthreads_8c_source.html">chthreads.c</a>.</p>
<p>References <aclass="el"href="group__debug.html#ga6bb6c0f97caab3a66332c8bfbf7a3844">chDbgCheck</a>, <aclass="el"href="group__scheduler.html#ga4e38b4bee3d2330f6a0f1cdb7660af20">chSchRescheduleS()</a>, <aclass="el"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42">chSysLock</a>, <aclass="el"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e">chSysUnlock</a>, <aclass="el"href="group__scheduler.html#ga1a5fddde56420e8accd0c09c1abb32a7">currp</a>, <aclass="el"href="group__scheduler.html#ga0621c307e30868052b802fbc821297e8">HIGHPRIO</a>, and <aclass="el"href="group__scheduler.html#ga38aff897bc7950077d5985b3d4bcf4d5">LOWPRIO</a>.</p>
<p>Referenced by <aclass="el"href="classchibios__rt_1_1_base_thread.html#aa824957049b5d62a4d23b0c9758b30a5">chibios_rt::BaseThread::SetPriority()</a>.</p>
<areashape="rect"id="node3"href="group__scheduler.html#ga4e38b4bee3d2330f6a0f1cdb7660af20"title="Performs a reschedule if a higher priority thread is runnable."alt=""coords="155,5,272,32"/><areashape="rect"id="node5"href="group__scheduler.html#ga0257cf203e72a766a52059750cb97e6e"title="Switches to the first thread on the runnable queue."alt=""coords="320,5,445,32"/></map>
<p>Definition at line <aclass="el"href="chthreads_8c_source.html#l00310">310</a> of file <aclass="el"href="chthreads_8c_source.html">chthreads.c</a>.</p>
<areashape="rect"id="node3"href="group__scheduler.html#gae47a8819a21ef2d521124e76bfb37c95"title="Wakes up a thread."alt=""coords="144,31,243,57"/><areashape="rect"id="node5"href="group__debug.html#gac7f8f0653faf2e3a93108ff5333821b7"title="Inserts in the circular debug trace buffer a context switch record."alt=""coords="295,5,375,32"/><areashape="rect"id="node7"href="group__scheduler.html#ga535d58cfb3436c8d4e4586c31c062298"title="Inserts a thread in the Ready List."alt=""coords="292,56,377,83"/></map>
<dlclass="note"><dt><b>Note:</b></dt><dd>The thread is not terminated but a termination request is added to its <code>p_flags</code> field. The thread can read this status by invoking <code><aclass="el"href="group__threads.html#ga5591a9f97ff77b40bd5fc29f16f12a6b"title="Verifies if the current thread has a termination request pending.">chThdShouldTerminate()</a></code> and then terminate cleanly.</dd></dl>
<dl><dt><b>Parameters:</b></dt><dd>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>tp</em> </td><td>pointer to the thread </td></tr>
<p>Definition at line <aclass="el"href="chthreads_8c_source.html#l00329">329</a> of file <aclass="el"href="chthreads_8c_source.html">chthreads.c</a>.</p>
<p>References <aclass="el"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42">chSysLock</a>, <aclass="el"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e">chSysUnlock</a>, and <aclass="el"href="struct_thread.html#a1e044ddc7521288d6fb473756a214d23">Thread::p_flags</a>.</p>
<p>Referenced by <aclass="el"href="classchibios__rt_1_1_base_thread.html#a9391836cb66a13932044703d1833ae64">chibios_rt::BaseThread::Terminate()</a>.</p>
<p>Suspends the invoking thread for the specified time. </p>
<dl><dt><b>Parameters:</b></dt><dd>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>time</em> </td><td>the delay in system ticks, the special values are handled as follow:</p>
<ul>
<li><em>TIME_INFINITE</em> the thread enters an infinite sleep state.</li>
<li><em>TIME_IMMEDIATE</em> this value is accepted but interpreted as a normal time specification not as an immediate timeout specification.</li>
<p>Definition at line <aclass="el"href="chthreads_8c_source.html#l00348">348</a> of file <aclass="el"href="chthreads_8c_source.html">chthreads.c</a>.</p>
<p>Definition at line <aclass="el"href="chthreads_8c_source.html#l00363">363</a> of file <aclass="el"href="chthreads_8c_source.html">chthreads.c</a>.</p>
<p>References <aclass="el"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42">chSysLock</a>, <aclass="el"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e">chSysUnlock</a>, <aclass="el"href="group__threads.html#ga851dc0c4ac72885bf09feebdef4673ac">chThdSleepS</a>, and <aclass="el"href="group__time.html#ga137c8f67c450f34416a786d169be90e2">chTimeNow</a>.</p>
<p>Referenced by <aclass="el"href="classchibios__rt_1_1_base_thread.html#a0589beba9bb4c959b3f49a82b24562eb">chibios_rt::BaseThread::SleepUntil()</a>.</p>
<p>Definition at line <aclass="el"href="chthreads_8c_source.html#l00376">376</a> of file <aclass="el"href="chthreads_8c_source.html">chthreads.c</a>.</p>
<p>References <aclass="el"href="group__scheduler.html#ga8fd763c1a004a010fc13575578edefbd">chSchDoYieldS</a>, <aclass="el"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42">chSysLock</a>, and <aclass="el"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e">chSysUnlock</a>.</p>
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>msg</em> </td><td>thread exit code. The code can be retrieved by using <code><aclass="el"href="group__threads.html#ga94a5727ecdbe0f738dfc8e1ede1c3409"title="Blocks the execution of the invoking thread until the specified thread terminates then the exit code ...">chThdWait()</a></code>. </td></tr>
<p>Definition at line <aclass="el"href="chthreads_8c_source.html#l00389">389</a> of file <aclass="el"href="chthreads_8c_source.html">chthreads.c</a>.</p>
<areashape="rect"id="node3"href="group__scheduler.html#ga97c1c514b755a1e71caf2f19c1ccf986"title="Puts the current thread to sleep into the specified state."alt=""coords="123,31,224,57"/><areashape="rect"id="node9"href="group__scheduler.html#ga535d58cfb3436c8d4e4586c31c062298"title="Inserts a thread in the Ready List."alt=""coords="131,81,216,108"/><areashape="rect"id="node11"href="group__internals.html#gad9aa523aebdaeefa3cc4a311bc210e8a"title="Pops a Thread from the top of a stack list and returns it."alt=""coords="135,132,212,159"/><areashape="rect"id="node5"href="group__debug.html#gac7f8f0653faf2e3a93108ff5333821b7"title="Inserts in the circular debug trace buffer a context switch record."alt=""coords="273,5,353,32"/><areashape="rect"id="node7"href="group__internals.html#ga042479f09357fc59befebf4dfe0e9f4a"title="Removes the first-out Thread from a queue and returns it."alt=""coords="273,56,353,83"/></map>
<p>Definition at line <aclass="el"href="chthreads_8c_source.html#l00418">418</a> of file <aclass="el"href="chthreads_8c_source.html">chthreads.c</a>.</p>
<p>If the references counter reaches zero <b>and</b> the thread is in the <code>THD_STATE_FINAL</code> state then the thread's memory is returned to the proper allocator. </p>
<dlclass="note"><dt><b>Note:</b></dt><dd>Static threads are not affected.</dd></dl>
<dl><dt><b>Parameters:</b></dt><dd>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>tp</em> </td><td>pointer to the thread </td></tr>
<p>Definition at line <aclass="el"href="chthreads_8c_source.html#l00436">436</a> of file <aclass="el"href="chthreads_8c_source.html">chthreads.c</a>.</p>
<p>Referenced by <aclass="el"href="group__registry.html#gaefff43a49fb7888a596319d67cf01dab">chRegNextThread()</a>, and <aclass="el"href="group__threads.html#ga94a5727ecdbe0f738dfc8e1ede1c3409">chThdWait()</a>.</p>
<areashape="rect"id="node3"href="group__heaps.html#ga0fc553df0138f02e0b233be91e413c79"title="Frees a previously allocated memory block."alt=""coords="145,5,225,32"/><areashape="rect"id="node5"href="group__pools.html#ga978f8d038e8e981bf9e5a104b81c6cb6"title="Releases (or adds) an object into (to) a memory pool."alt=""coords="148,56,223,83"/><areashape="rect"id="node7"href="group__pools.html#gab5c6c04fd14fbeee2183ca955371c515"title="Releases (or adds) an object into (to) a memory pool."alt=""coords="276,56,353,83"/></map>
<p>Blocks the execution of the invoking thread until the specified thread terminates then the exit code is returned. </p>
<p>This function waits for the specified thread to terminate then decrements its reference counter, if the counter reaches zero then the thread working area is returned to the proper allocator.<br/>
The memory used by the exited thread is handled in different ways depending on the API that spawned the thread:</p>
<li>If the thread was spawned by <code><aclass="el"href="group__threads.html#ga048e588238dd336c6059133b3d0c3435"title="Creates a new thread into a static memory area.">chThdCreateStatic()</a></code> or by <code>chThdInit()</code> then nothing happens and the thread working area is not released or modified in any way. This is the default, totally static, behavior.</li>
<li>If the thread was spawned by <code><aclass="el"href="group__threads.html#ga50b84e3e82a4e09c1066e1d422e4c780"title="Creates a new thread allocating the memory from the heap.">chThdCreateFromHeap()</a></code> then the working area is returned to the system heap.</li>
<li>If the thread was spawned by <code><aclass="el"href="group__threads.html#gad3ccc1a6f054c543258ed2fe97ed2f58"title="Creates a new thread allocating the memory from the specified memory pool.">chThdCreateFromMemoryPool()</a></code> then the working area is returned to the owning memory pool.</li>
<p>Please read the <aclass="el"href="article_lifecycle.html">Threads Lifecycle</a> article for more details. </p>
<dlclass="note"><dt><b>Note:</b></dt><dd>After invoking <code><aclass="el"href="group__threads.html#ga94a5727ecdbe0f738dfc8e1ede1c3409"title="Blocks the execution of the invoking thread until the specified thread terminates then the exit code ...">chThdWait()</a></code> the thread pointer becomes invalid and must not be used as parameter for further system calls. </dd>
The function is available only if the <code>CH_USE_WAITEXIT</code> option is enabled in <code><aclass="el"href="chconf_8h.html"title="Configuration file template.">chconf.h</a></code>. </dd>
<dd>
If <code>CH_USE_DYNAMIC</code> is not specified this function just waits for the thread termination, no memory allocators are involved.</dd></dl>
<dl><dt><b>Parameters:</b></dt><dd>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>tp</em> </td><td>pointer to the thread </td></tr>
</table>
</dd>
</dl>
<dlclass="return"><dt><b>Returns:</b></dt><dd>The exit code from the terminated thread. </dd></dl>
<p>Definition at line <aclass="el"href="chthreads_8c_source.html#l00499">499</a> of file <aclass="el"href="chthreads_8c_source.html">chthreads.c</a>.</p>
<areashape="rect"id="node3"href="group__scheduler.html#ga97c1c514b755a1e71caf2f19c1ccf986"title="Puts the current thread to sleep into the specified state."alt=""coords="128,56,229,83"/><areashape="rect"id="node9"href="group__threads.html#gaa22f80040cf192015be4607f31a0ac80"title="Releases a reference to a thread object."alt=""coords="133,107,224,133"/><areashape="rect"id="node15"href="group__internals.html#ga5818ce2d363d36402baece614b06e41b"title="Pushes a Thread on top of a stack list."alt=""coords="145,157,212,184"/><areashape="rect"id="node5"href="group__debug.html#gac7f8f0653faf2e3a93108ff5333821b7"title="Inserts in the circular debug trace buffer a context switch record."alt=""coords="279,5,359,32"/><areashape="rect"id="node7"href="group__internals.html#ga042479f09357fc59befebf4dfe0e9f4a"title="Removes the first-out Thread from a queue and returns it."alt=""coords="279,56,359,83"/><areashape="rect"id="node11"href="group__heaps.html#ga0fc553df0138f02e0b233be91e413c79"title="Frees a previously allocated memory block."alt=""coords="279,107,359,133"/><areashape="rect"id="node13"href="group__pools.html#ga978f8d038e8e981bf9e5a104b81c6cb6"title="Releases (or adds) an object into (to) a memory pool."alt=""coords="281,157,356,184"/></map>
Generated on Sun Nov 28 2010 14:09:56 for ChibiOS/RT by <ahref="http://www.doxygen.org/index.html"><imgsrc="doxygen.png"alt="doxygen"align="middle"border="0"></a> 1.7.1</small></address>