1 <!-- Copyright (C) 2003 Red Hat, Inc. -->
2 <!-- This material may be distributed only subject to the terms -->
3 <!-- and conditions set forth in the Open Publication License, v1.0 -->
4 <!-- or later (the latest version is presently available at -->
5 <!-- http://www.opencontent.org/openpub/). -->
6 <!-- Distribution of the work or derivative of the work in any -->
7 <!-- standard (paper) book form is prohibited unless prior -->
8 <!-- permission is obtained from the copyright holder. -->
12 >Thread termination</TITLE
13 ><meta name="MSSmartTagsPreventParsing" content="TRUE">
16 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
19 TITLE="eCos Reference Manual"
20 HREF="ecos-ref.html"><LINK
22 TITLE="The eCos Kernel"
23 HREF="kernel.html"><LINK
25 TITLE="Thread control"
26 HREF="kernel-thread-control.html"><LINK
28 TITLE="Thread priorities"
29 HREF="kernel-thread-priorities.html"></HEAD
40 SUMMARY="Header navigation table"
49 >eCos Reference Manual</TH
57 HREF="kernel-thread-control.html"
71 HREF="kernel-thread-priorities.html"
82 NAME="KERNEL-THREAD-TERMINATION">Thread termination</H1
90 >cyg_thread_exit, cyg_thread_kill, cyg_thread_delete -- Allow threads to terminate</DIV
92 CLASS="REFSYNOPSISDIV"
108 CLASS="FUNCSYNOPSISINFO"
109 >#include <cyg/kernel/kapi.h>
118 >void cyg_thread_exit</CODE
125 >void cyg_thread_kill</CODE
126 >(cyg_handle_t thread);</CODE
132 >void cyg_thread_delete</CODE
133 >(cyg_handle_t thread);</CODE
147 >In many embedded systems the various threads are allocated statically,
148 created during initialization, and never need to terminate. This
149 avoids any need for dynamic memory allocation or other resource
150 management facilities. However if a given application does have a
151 requirement that some threads be created dynamically, must terminate,
152 and their resources such as the stack be reclaimed, then the kernel
153 provides the functions <TT
163 >cyg_thread_delete</TT
170 > allows a thread to terminate
171 itself, thus ensuring that it will not be run again by the scheduler.
175 > data structure passed
178 >cyg_thread_create</TT
179 > remains in use, and the
180 handle returned by <TT
182 >cyg_thread_create</TT
184 valid. This allows other threads to perform certain operations on the
185 terminated thread, for example to determine its stack usage via
188 >cyg_thread_measure_stack_usage</TT
193 > structure are no longer
196 >cyg_thread_delete</TT
197 > should be called to
198 release these resources. If the stack was dynamically allocated then
199 this should not be freed until after the call to
202 >cyg_thread_delete</TT
206 >Alternatively, one thread may use <TT
210 on another This has much the same effect as the affected thread
214 >. However killing a thread
215 is generally rather dangerous because no attempt is made to unlock any
216 synchronization primitives currently owned by that thread or release
217 any other resources that thread may have claimed. Therefore use of
218 this function should be avoided, and
226 > cannot be used by a thread to
232 >cyg_thread_delete</TT
233 > should be used on a thread
234 after it has exited and is no longer required. After this call the
235 thread handle is no longer valid, and both the
239 > structure and the thread stack can
240 be re-used or freed. If <TT
242 >cyg_thread_delete</TT
244 invoked on a thread that is still running then there is an implicit
254 NAME="KERNEL-THREAD-TERMINATION-CONTEXT"
269 >cyg_thread_delete</TT
270 > can only be called from thread
279 SUMMARY="Footer navigation table"
290 HREF="kernel-thread-control.html"
308 HREF="kernel-thread-priorities.html"
332 >Thread priorities</TD