# OS_SetThreadDestructor

## C Specification

      #include <nitro/os.h>

      void OS_SetThreadDestructor( OSThread* thread, OSThreadDestructor dtor );

## Arguments

thread | Pointer to the thread structure used to set the destructor
dtor | Destructor function

## Return Values

None.

## Description

This function sets the destructor function to be called when a thread ends.

The thread is specified by thread.dtor is a pointer to a function of `OSThreadDestructor` type. The `OSThreadDestructor` type is defined as follows.

`typedef void (*OSThreadDestructor)( void* );`

The destructor function is called when a thread ends under the following conditions.

> -When the thread finishes executing its task
> -When it ends with `OS_ExitThread()`
> -When terminated from another thread using `OS_KillThread*()`
> - When it terminates itself with `OS_KillThread*()`

A destructor function is not called in the following situations.

> EAnother thread using `OS_DestroyThread()`terminates the thread
> -When the thread terminates itself using `OS_DestroyThread()`

When the destructor function is executed, execution switches to the context of the thread that is terminated. The stack pointer is then updated (described later). The destructor is called before internal thread information is changed. Interrupts are disabled during this time.

The stack for executing the destructor function is updated to have the highest priority (excluding code used for checking) by default. You can change it to the specified stack using `OS_SetThreadDestructorStack()`.

## See Also

`OS_InitThread,` `OS_ExitThread, OS_DestroyThread, OS_KillThread*`
`OS_GetThreadDestructor, OS_SetThreadDestructorStack
`

## Revision History

2005/08/09 Added description of `OS_SetThreadDestructorStack`.
07/07/2005 Added description of conditions under which the destructor is called.
06/30/2005 Initial version.

CONFIDENTIAL