TlsGetValue

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

Syntax

LPVOID TlsGetValue(
    DWORD TlsIndex
);

Parameters

TlsIndex

The TLS index that was allocated by TlsAlloc.

Return Value

The value stored in the calling thread's TLS slot associated with the specified index if the function succeeds, 0 (zero) if the function fails

To get extended error information, call GetLastError.

NOTE: The data stored in a TLS slot can have a value of zero. In this case, the return value is zero and GetLastError returns NO_ERROR.

Remarks

TLS indexes are typically allocated by TlsAlloc during process or DLL initialization. Once allocated, each thread of the process can use a TLS index to access its own TLS storage slot for that index. The storage slot for each thread is initialized to NULL. 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 and TlsGetValue were implemented with speed as the primary goal. These functions perform minimal parameter validation and error checking. In particular, this function succeeds if TlsIndex is in the range 0 through (TLS_MINIMUM_AVAILABLE - 1). It is up to the programmer to ensure that the index is valid.

Windows functions that return indications of failure call SetLastError when they fail. They generally do not call SetLastError when they succeed. TlsGetValue is an exception to this general rule; it calls SetLastError to clear a thread's last error when it succeeds. That allows checking for the error-free retrieval of NULL values.

Requirements

Minimum Supported Version RTX64 2013
Header windows.h
Library Rtx_Rtss.lib

See Also:

GetLastError

SetLastError

TlsAlloc

TlsFree

TlsSetValue