---
name: "Thread.h"
section: "3"
platform: "linux"
package: "libzycore-doc"
version: "1.5.2-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Thread.h"
---

# Thread.h(3)

## NAME

include/Zycore/API/Thread.h

## SYNOPSIS

`#include <Zycore/Defines.h>`\
 `#include <Zycore/Status.h>`\

### Functions

**ZYCORE\_EXPORT** **ZyanStatus** **ZyanThreadGetCurrentThread** (ZyanThread \*thread)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanThreadGetCurrentThreadId** (ZyanThreadId \*thread\_id)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanThreadTlsAlloc** (ZyanThreadTlsIndex \*index, ZyanThreadTlsCallback destructor)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanThreadTlsFree** (ZyanThreadTlsIndex index)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanThreadTlsGetValue** (ZyanThreadTlsIndex index, void \*\*data)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanThreadTlsSetValue** (ZyanThreadTlsIndex index, void \*data)\

## Function Documentation

### ZYCORE\_EXPORT ZyanStatus ZyanThreadGetCurrentThread (ZyanThread \* thread)

Returns the handle of the current thread.

**Parameters**

*thread* Receives the handle of the current thread.

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanThreadGetCurrentThreadId (ZyanThreadId \* thread\_id)

Returns the unique id of the current thread.

**Parameters**

*thread\_id* Receives the unique id of the current thread.

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanThreadTlsAlloc (ZyanThreadTlsIndex \* index, ZyanThreadTlsCallback destructor)

Allocates a new Thread Local Storage (TLS) slot.

**Parameters**

*index* Receives the TLS slot index. \
 *destructor* A pointer to a destructor callback which is invoked to finalize the data in the TLS slot or `ZYAN_NULL`, if not needed.

The maximum available number of TLS slots is implementation specific and different on each platform:

- •

  Windows

- •

  A total amount of 128 slots per process are guaranteed

- •

  POSIX

- •

  A total amount of 128 slots per process are guaranteed

- •

  Some systems guarantee larger amounts like e.g. 1024 slots per process

Note that the invocation rules for the destructor callback are implementation specific and different on each platform:

- •

  Windows

- •

  The callback is invoked when a thread exits

- •

  The callback is invoked when the process exits

- •

  The callback is invoked when the TLS slot is released

- •

  POSIX

- •

  The callback is invoked when a thread exits and the stored value is not null

- •

  The callback is NOT invoked when the process exits

- •

  The callback is NOT invoked when the TLS slot is released

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanThreadTlsFree (ZyanThreadTlsIndex index)

Releases a Thread Local Storage (TLS) slot.

**Parameters**

*index* The TLS slot index.

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanThreadTlsGetValue (ZyanThreadTlsIndex index, void \*\* data)

Returns the value inside the given Thread Local Storage (TLS) slot for the calling thread.

**Parameters**

*index* The TLS slot index. \
 *data* Receives the value inside the given Thread Local Storage (TLS) slot for the calling thread.

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanThreadTlsSetValue (ZyanThreadTlsIndex index, void \* data)

Set the value of the given Thread Local Storage (TLS) slot for the calling thread.

**Parameters**

*index* The TLS slot index. \
 *data* The value to store inside the given Thread Local Storage (TLS) slot for the calling thread

**Returns**

A zyan status code.

## Author

Generated automatically by Doxygen for Zycore from the source code.
