---
name: "SDL_SetTLS"
section: "3"
platform: "linux"
package: "libsdl3-doc"
version: "3.2.10+ds-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/SDL_SetTLS"
---

# SDL\_SetTLS(3)

Set the current thread's value associated with a thread local storage ID.

## NAME

SDL\_SetTLS - Set the current thread's value associated with a thread local storage ID.

## HEADER FILE

Defined in SDL3/SDL\_thread.h

## SYNOPSIS

```
#include "SDL3/SDL.h"
```

**bool SDL\_SetTLS(SDL\_TLSID \*id, const void \*value, SDL\_TLSDestructorCallback destructor);**

## DESCRIPTION

If the thread local storage ID is not initialized (the value is 0), a new ID will be created in a thread-safe way, so all calls using a pointer to the same ID will refer to the same local storage.

Note that replacing a value from a previous call to this function on the same thread does \_not\_ call the previous value's destructor! **destructor** can be NULL; it is assumed that **value** does not need to be cleaned up if so.

## FUNCTION PARAMETERS

- *id*

  a pointer to the thread local storage ID, may not be NULL.

- *value*

  the value to associate with the ID for the current thread.

- *destructor*

  a function called when the thread exits, to free the value, may be NULL.

## RETURN VALUE

Returns true on success or false on failure; call

**SDL\_GetError** () for more information.

## THREAD SAFETY

It is safe to call this function from any thread.

## AVAILABILITY

This function is available since SDL 3.2.0.

## SEE ALSO

**•**(3), [**SDL\_GetTLS**(3)](/SDL_GetTLS/3.md)
