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_set.html | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 devdocs/c/thread%2Ftss_set.html (limited to 'devdocs/c/thread%2Ftss_set.html') diff --git a/devdocs/c/thread%2Ftss_set.html b/devdocs/c/thread%2Ftss_set.html new file mode 100644 index 00000000..88b4629a --- /dev/null +++ b/devdocs/c/thread%2Ftss_set.html @@ -0,0 +1,29 @@ +

tss_set

Defined in header <threads.h>
int tss_set( tss_t tss_id, void *val );
+
(since C11)

Sets the value of the thread-specific storage identified by tss_id for the current thread to val. Different threads may set different values to the same key.

+

The destructor, if available, is not invoked.

+

Parameters

+ + +
tss_id - thread-specific storage key, obtained from tss_create and not deleted by tss_delete
val - value to set thread-specific storage to

Return value

thrd_success if successful, thrd_error otherwise.

+

Notes

The POSIX equivalent of this function is pthread_setspecific.

+

Typically TSS is used to store pointers to blocks of dynamically allocated memory that have been reserved for use by the calling thread.

+

tss_set may be called in the TSS destructor. If the destructor exits with non-NULL value in the TSS storage, it will be retried by thrd_exit up to TSS_DTOR_ITERATIONS times, after which the storage will be lost.

+

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

See also

+
+
(C11)
reads from thread-specific storage
(function)
+

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

+
-- cgit v1.2.3