|
noexcept |
Creates a thread-specific storage (TSS) key with an optional destructor used during releasing thread specific storages associated with the key.
[out] | pKey | is a buffer, on output receiving a key identifying the storage. The key is used in the TSS managing functions. |
[in] | dtor | is an optional chsv_tss_dtor_t pointer to a user defined destructor to dispose resources associated with the storage. |
The function creates a thread-specific data key visible to all threads within the process. The key is used to identify data associated with the key independently for each thread. The values bound to the key by chsv_tss_set are maintained on a per-thread basis and persist for the life of the calling thread.
Upon the key creation the NULL value is associated with the key in all active threads as well as threads to be created later (but before chsv_tss_delete is called over the key).
An optional destructor function may be associated with each key value. At thread exit, if a key value has a non-NULL destructor pointer, and the thread has a non-NULL value associated with that key, the value of the key is set to NULL, and then the function pointed to by dtor is called with the previously associated value as its sole argument.
If, after all the destructors have been called for all non-NULL values with associated destructors, there are still some non-NULL values with associated destructors, then the process is repeated. If, after at least CHSV_TSS_DTOR_ITERATIONS iterations of destructor calls for outstanding non-NULL values, there are still some non-NULL values with associated destructors the destruction process stops.
The function implements a behaviour of the tss_create function defined in the ISO/IEC 9899:2011 (aka C11) standard.