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_SetThreadDestructor</TITLE>
8<LINK rel="stylesheet" href="../../css/nitro.css" type="text/css">
9</HEAD>
10<BODY>
11<H1 align="left">OS_SetThreadDestructor <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_SetThreadDestructor( OSThread* thread, OSThreadDestructor dtor );</CODE></PRE>
17</DL>
18<H2>Arguments</H2>
19<TABLE border="1" width="100%">
20  <TBODY>
21    <TR>
22      <TD width="13%"><EM><STRONG>thread</STRONG></EM></TD>
23      <TD width="87%">Pointer to the thread structure used to set the destructor.</TD>
24    </TR>
25    <TR>
26      <TD width="13%"><EM><STRONG>dtor</STRONG></EM></TD>
27      <TD width="87%">Destructor function.</TD>
28    </TR>
29  </TBODY>
30</TABLE>
31<H2>Return Values</H2>
32<P>None.</P>
33<H2>Description</H2>
34<P>This function sets the destructor function to be called when a thread ends.</P>
35<P>The thread is specified by <EM><B>thread</B></EM>. <STRONG><B><EM>dtor</EM></B></STRONG> is a pointer to a function of type <CODE>OSThreadDestructor</CODE>. The <CODE>OSThreadDestructor</CODE> type is defined as:</P>
36<P>    <CODE>typedef void (*OSThreadDestructor)( void* );</CODE></P>
37<P> </P>
38<P>The destructor function is called when a thread ends under the following conditions:</P>
39<BLOCKQUOTE>- When the thread finishes executing its task <BR> - When it ended with <CODE><A href="OS_ExitThread.html">OS_ExitThread()</A></CODE><BR>- When it was terminated from another thread with <CODE><A href="OS_KillThread.html">OS_KillThread*()</A></CODE><BR>- When it terminated itself with <CODE><A href="OS_KillThread.html">OS_KillThread*()</A></CODE></BLOCKQUOTE>
40<P>A destructor function is not called in the following situations.</P>
41<BLOCKQUOTE>- When the thread was terminated by another thread using <CODE><A href="OS_DestroyThread.html">OS_DestroyThread()</A></CODE> <BR> - When the thread terminated itself using <CODE><A href="OS_DestroyThread.html">OS_DestroyThread()</A></CODE></BLOCKQUOTE>
42<P>When the destructor function is run, execution switches to the context of the thread that ends. The stack pointer is then updated (described later). The destructor is called while the thread is in interrupt-prohibited state, before internal thread information is changed.</P>
43<P>At the time the destructor function is executed, the stack is shifted to highest priority by default (excluding the code used for checking). You can change it to the specified stack using <CODE><A href="OS_SetThreadDestructorStack.html">OS_SetThreadDestructorStack()</A></CODE>.</P>
44<P><FONT color="#ff0033">Do not release the prohibition on interrupts inside the destructor function or call any functions that generate thread scheduling, because this may cause mismatching to arise in the thread list.</FONT></P>
45<H2>See Also</H2>
46<P><A href="OS_InitThread.html"><CODE>OS_InitThread</CODE></A>, <A href="OS_ExitThread.html"><CODE>OS_ExitThread</CODE></A>, <A href="OS_DestroyThread.html"><CODE>OS_DestroyThread</CODE></A>, <A href="OS_KillThread.html"><CODE>OS_KillThread*</CODE></A>, <A href="OS_GetThreadDestructor.html"><CODE>OS_GetThreadDestructor</CODE></A>, <A href="OS_SetThreadDestructorStack.html"><CODE>OS_SetThreadDestructorStack</CODE></A></P>
47<H2>Revision History</H2>
48<P>2007/08/20 Added notes about operations inside the destructor function.<BR>2005/08/09 Added text about <CODE><A href="OS_SetThreadDestructorStack.html">OS_SetThreadDestructorStack</A></CODE>.<BR>2005/07/07 Added text about conditions under which destructor function is called.<BR>2005/06/30 Initial version.</P>
49<hr><p>CONFIDENTIAL</p></body>
50</HTML>