From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/c/thread%2Ftss_create.html | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 devdocs/c/thread%2Ftss_create.html (limited to 'devdocs/c/thread%2Ftss_create.html') diff --git a/devdocs/c/thread%2Ftss_create.html b/devdocs/c/thread%2Ftss_create.html new file mode 100644 index 00000000..749b3ebd --- /dev/null +++ b/devdocs/c/thread%2Ftss_create.html @@ -0,0 +1,27 @@ +

tss_create

Defined in header <threads.h>
int tss_create( tss_t* tss_key, tss_dtor_t destructor );
+
(since C11)

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.

+

The value NULL is associated with the newly created key in all existing threads, and upon thread creation, the values associated with all TSS keys is initialized to NULL.

+

If destructor is not a null pointer, then also associates the destructor which is called when the storage is released by thrd_exit (but not by tss_delete and not at program termination by exit).

+

A call to tss_create from within a thread-specific storage destructor results in undefined behavior.

+

Parameters

+ + +
tss_key - pointer to memory location to store the new thread-specific storage key
destructor - pointer to a function to call at thread exit

Notes

The POSIX equivalent of this function is pthread_key_create.

+

Return value

thrd_success if successful, thrd_error otherwise.

+

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

References

+

+ © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
+ https://en.cppreference.com/w/c/thread/tss_create +

+
-- cgit v1.2.3