Windows Dev Center

Expand Minimize

TlsSetValue function

Stores a value in the calling thread's thread local storage (TLS) slot for the specified TLS index. Each thread of a process has its own slot for each TLS index.

Syntax


BOOL WINAPI TlsSetValue(
  _In_     DWORD  dwTlsIndex,
  _In_opt_ LPVOID lpTlsValue
);

Parameters

dwTlsIndex [in]

The TLS index that was allocated by the TlsAlloc function.

lpTlsValue [in, optional]

The value to be stored in the calling thread's TLS slot for the index.

Return value

If the function succeeds, the return value is nonzero.

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

Remarks

Windows Phone 8.1: This function is supported for Windows Phone Store apps on Windows Phone 8.1 and later. When a Windows Phone Store app calls this function, it is replaced with an inline call to FlsSetValue. Refer to FlsSetValue for function documentation.

Windows 8.1 and Windows Server 2012 R2: This function is supported for Windows Store apps on Windows 8.1, Windows Server 2012 R2, and later. When a Windows Store app calls this function, it is replaced with an inline call to FlsSetValue. Refer to FlsSetValue for function documentation.

TLS indexes are typically allocated by the TlsAlloc function during process or DLL initialization. When a TLS index is allocated, its storage slots are initialized to NULL. After a TLS index is allocated, each thread of the process can use it to access its own TLS slot for that index. A thread specifies a TLS index in a call to TlsSetValue, to store a value in its slot. The thread specifies the same index in a subsequent call to TlsGetValue, to retrieve the stored value.

TlsSetValue was implemented with speed as the primary goal. The function performs minimal parameter validation and error checking. In particular, it succeeds if dwTlsIndex is in the range 0 through (TLS_MINIMUM_AVAILABLE – 1). It is up to the programmer to ensure that the index is valid before calling TlsGetValue.

Examples

For an example, see Using Thread Local Storage or Using Thread Local Storage in a Dynamic-Link Library.

Requirements

Minimum supported client

Windows XP [desktop apps only]

Minimum supported server

Windows Server 2003 [desktop apps only]

Minimum supported phone

Windows Phone 8.1

Header

WinBase.h on Windows Server 2003, Windows Vista, Windows 7, Windows Server 2008, and Windows Server 2008 R2 (include Windows.h);
Processthreadsapi.h on Windows 8, Windows Server 2012, and Windows Phone 8.1

Library

Kernel32.lib;
WindowsPhoneCore.lib on Windows Phone 8.1

DLL

KernelBase.dll on Windows Phone 8.1;
Kernel32.dll

See also

Process and Thread Functions
Thread Local Storage
TlsAlloc
TlsFree
TlsGetValue

 

 

Community Additions

ADD
Show:
© 2015 Microsoft