CKTIS / C
tss_get — read a thread-specific pointer
tss_get reads the pointer stored under a thread-specific storage key for the calling thread.
Version: C23; repository compiler flag, production runtime not attested
Syntax
#include <threads.h>
void *tss_get(tss_t key);tss_get(key) from <threads.h> returns the calling thread’s associated void *. The same key can hold different pointers in different threads.
The initial value is NULL; tss_set changes it. A zero result also indicates failure, so it cannot distinguish a stored NULL from failure.
The key must come from successful tss_create before the thread began executing destructors. Do not use it after tss_delete. Reading does not copy the pointed-to object: manage its lifetime. tss_delete does not invoke its destructor.
Examples
#include <stdio.h>
#include <stdlib.h>
#include <threads.h>
int main(void)
{
tss_t key;
int value = 42;
if (tss_create(&key, NULL) != thrd_success)
return EXIT_FAILURE;
printf("initial_null=%d\n", tss_get(key) == NULL);
if (tss_set(key, &value) != thrd_success) {
tss_delete(key);
return EXIT_FAILURE;
}
int *p = tss_get(key);
if (p != &value) {
tss_delete(key);
return EXIT_FAILURE;
}
printf("value=%d\n", *p);
tss_delete(key);
return EXIT_SUCCESS;
}
Result
initial_null=1 value=42
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.