tss_create

Header: <threads.h>

Creates new thread-specific storage key and stores it in the object pointed to by tss_key. Although the same key value may be used by different threads, the values bound to the key by tss_set are maintained on a per-thread basis and persist for the life of the calling thread.

# Declarations

int tss_create( tss_t* tss_key, tss_dtor_t destructor );

(since C11)

# Parameters

# Return value

thrd_success if successful, thrd_error otherwise.

# Notes

The POSIX equivalent of this function is pthread_key_create.

# Example

int thread_func(void *arg) {
    tss_t key;
    if (thrd_success == tss_create(&key, free)) {
        tss_set(key, malloc(4)); // stores a pointer on TSS
        // ...
    }
} // calls free() for the pointer stored on TSS