diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/c/thread%2Ftss_create.html | |
new repository
Diffstat (limited to 'devdocs/c/thread%2Ftss_create.html')
| -rw-r--r-- | devdocs/c/thread%2Ftss_create.html | 27 |
1 files changed, 27 insertions, 0 deletions
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 @@ + <h1 id="firstHeading" class="firstHeading">tss_create</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><threads.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c11"> <td> <pre data-language="c">int tss_create( tss_t* tss_key, tss_dtor_t destructor );</pre> +</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c11">(since C11)</span> </td> </tr> </table> <p>Creates new thread-specific storage key and stores it in the object pointed to by <code>tss_key</code>. Although the same key value may be used by different threads, the values bound to the key by <code><a href="tss_set" title="c/thread/tss set">tss_set</a></code> are maintained on a per-thread basis and persist for the life of the calling thread.</p> +<p>The value <code><a href="../types/null" title="c/types/NULL">NULL</a></code> 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 <code><a href="../types/null" title="c/types/NULL">NULL</a></code>.</p> +<p>If <code>destructor</code> is not a null pointer, then also associates the destructor which is called when the storage is released by <code><a href="thrd_exit" title="c/thread/thrd exit">thrd_exit</a></code> (but not by <code><a href="tss_delete" title="c/thread/tss delete">tss_delete</a></code> and not at program termination by <code><a href="../program/exit" title="c/program/exit">exit</a></code>).</p> +<p>A call to <code>tss_create</code> from within a thread-specific storage destructor results in undefined behavior.</p> +<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> tss_key </td> <td> - </td> <td> pointer to memory location to store the new thread-specific storage key </td> +</tr> <tr class="t-par"> <td> destructor </td> <td> - </td> <td> pointer to a function to call at thread exit </td> +</tr> +</table> <h3 id="Notes"> Notes</h3> <p>The POSIX equivalent of this function is <a rel="nofollow" class="external text" href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_key_create.html"><code>pthread_key_create</code></a>.</p> +<h3 id="Return_value"> Return value</h3> <p><code><a href="thrd_errors" title="c/thread/thrd errors">thrd_success</a></code> if successful, <code><a href="thrd_errors" title="c/thread/thrd errors">thrd_error</a></code> otherwise.</p> +<h3 id="Example"> Example</h3> <div class="c source-c"><pre data-language="c">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</pre></div> <h3 id="References"> References</h3> <ul> +<li> C17 standard (ISO/IEC 9899:2018): </li> +<ul><li> 7.26.6.1 The tss_create function (p: 281-282) </li></ul> +<li> C11 standard (ISO/IEC 9899:2011): </li> +<ul><li> 7.26.6.1 The tss_create function (p: 386) </li></ul> +</ul> <div class="_attribution"> + <p class="_attribution-p"> + © cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br> + <a href="https://en.cppreference.com/w/c/thread/tss_create" class="_attribution-link">https://en.cppreference.com/w/c/thread/tss_create</a> + </p> +</div> |
