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 destructors</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="Per-thread data"
26 HREF="kernel-thread-data.html"><LINK
28 TITLE="Exception handling"
29 HREF="kernel-exceptions.html"></HEAD
40 SUMMARY="Header navigation table"
49 >eCos Reference Manual</TH
57 HREF="kernel-thread-data.html"
71 HREF="kernel-exceptions.html"
82 NAME="KERNEL-THREAD-DESTRUCTORS">Thread destructors</H1
90 >cyg_thread_add_destructor, cyg_thread_rem_destructor -- Call functions on thread termination</DIV
92 CLASS="REFSYNOPSISDIV"
108 CLASS="FUNCSYNOPSISINFO"
109 >#include <cyg/kernel/kapi.h>
112 >cyg_thread_destructor_fn</SPAN
115 >cyg_addrword_t</SPAN
125 >cyg_bool_t cyg_thread_add_destructor</CODE
126 >(cyg_thread_destructor_fn fn, cyg_addrword_t data);</CODE
132 >cyg_bool_t cyg_thread_rem_destructor</CODE
133 >(cyg_thread_destructor_fn fn, cyg_addrword_t data);</CODE
147 >These functions are provided for cases when an application requires a
148 function to be automatically called when a thread exits. This is often
149 useful when, for example, freeing up resources allocated by the thread.
152 >This support must be enabled with the configuration option
155 >CYGPKG_KERNEL_THREADS_DESTRUCTORS</TT
157 you may register a function of type
160 >cyg_thread_destructor_fn</SPAN
161 > to be called on thread
162 termination using <TT
164 >cyg_thread_add_destructor</TT
166 may also provide it with a piece of arbitrary information in the
172 > argument which will be passed to the
173 destructor function <TT
179 terminates. If you no longer wish to call a function previous
182 >cyg_thread_add_destructor</TT
186 >cyg_thread_rem_destructor</TT
188 parameters used to register the destructor function. Both these
199 >By default, thread destructors are per-thread, which means that registering
200 a destructor function only registers that function for the current thread.
201 In other words, each thread has its own list of destructors.
202 Alternatively you may disable the configuration option
205 >CYGSEM_KERNEL_THREADS_DESTRUCTORS_PER_THREAD</TT
207 case any registered destructors will be run when <SPAN
214 threads exit. In other words, the thread destructor list is global and all
215 threads have the same destructors.
218 >There is a limit to the number of destructors which may be registered,
219 which can be controlled with the
222 >CYGNUM_KERNEL_THREADS_DESTRUCTORS</TT
224 option. Increasing this value will very slightly increase the amount
225 of memory in use, and when
228 >CYGSEM_KERNEL_THREADS_DESTRUCTORS_PER_THREAD</TT
230 enabled, the amount of memory used per thread will increase. When the
231 limit has been reached, <TT
233 >cyg_thread_add_destructor</TT
244 NAME="KERNEL-THREAD-DESTRUCTORS-CONTEXT"
251 >CYGSEM_KERNEL_THREADS_DESTRUCTORS_PER_THREAD</TT
253 is enabled, these functions must only be called from a thread context
254 as they implicitly operate on the current thread. When
257 >CYGSEM_KERNEL_THREADS_DESTRUCTORS_PER_THREAD</TT
259 disabled, these functions may be called from thread or DSR context,
260 or at initialization time.
268 SUMMARY="Footer navigation table"
279 HREF="kernel-thread-data.html"
297 HREF="kernel-exceptions.html"
321 >Exception handling</TD