# OS_SetThreadStackWarningOffset

## C Specification

      #include <nitro/os.h>

      void OS_SetThreadStackWarningOffset( OSThread* thread, u32 offset );

## Arguments

thread | The thread for which you want to set a warning level.
offset | The warning level offset

## Return Values

None.

## Description

Sets up the warning level for checking for stack overflow with the specified thread

This check mechanism writes the magic number at the top and bottom positions of the stack by default. It checks by seeing if this was rewritten. `OS_SetThreadStackWarningOffset()` is added to the top and bottom positions and sets up a warning level in the middle. It writes the magic number for checking if this section was rewritten (The magic number of the stack top and bottom positions is already written when the thread is created.).)

The reason for setting magic code in the middle of the stack is to detect if a stack overflow may occur before the stack is used up to its bottom position and operation becomes indeterminate.

`offset` is the number of bytes from the bottom position of the stack and needs to be a multiple of 4. Setting a 0 releases this setting.

A magic number is written in the middle of the stack so operation can be suspended if it is currently being used. Therefore, always carry out settings for the portion of the stack that you are sure is not being used immediately after creating the thread.

> (Example)
> OS_CreateThread( &thread, ...); OS_SetThreadStackWarningOffset( &thread, 0x100);`OS_CheckStack( &thread );`

## See Also

`OS_CreateThread`, `OS_CheckStack`

## Revision History

04/29/2004 Revised description
01/21/2004 Initial version