This topic has not yet been rated - Rate this topic

SetThreadStackGuarantee function

Applies to: desktop apps only

Sets the minimum size of the stack associated with the calling thread or fiber that will be available during any stack overflow exceptions. This is useful for handling stack overflow exceptions; the application can safely use the specified number of bytes during exception handling.

Syntax

BOOL WINAPI SetThreadStackGuarantee(
  __inout  PULONG StackSizeInBytes
);

Parameters

StackSizeInBytes [in, out]

The size of the stack, in bytes. On return, this value is set to the size of the previous stack, in bytes.

If this parameter is 0 (zero), the function succeeds and the parameter contains the size of the current stack.

If the specified size is less than the current size, the function succeeds but ignores this request. Therefore, you cannot use this function to reduce the size of the stack.

This value cannot be larger than the reserved stack size.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is 0 (zero). To get extended error information, call GetLastError.

Remarks

If the function is successful, the application can handle possible EXCEPTION_STACK_OVERFLOW exceptions using structured exception handling. To resume execution after handling a stack overflow, you must perform certain recovery steps. If you are using the Microsoft C/C++ compiler, call the _resetstkoflw function. If you are using another compiler, see the documentation for the compiler for information on recovering from stack overflows.

To set the stack guarantee for a fiber, you must first call the SwitchToFiber function to execute the fiber. After you set the guarantee for this fiber, it is used by the fiber no matter which thread executes the fiber.

Requirements

Minimum supported client

Windows Vista, Windows XP Professional x64 Edition

Minimum supported server

Windows Server 2008, Windows Server 2003 with SP1

Header

WinBase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

Process and Thread Functions
Thread Stack Size
Threads

 

 

Send comments about this topic to Microsoft

Build date: 3/7/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ