Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      tss_create

      From cppreference.com
      <c‎ |thread
       
       
      Concurrency support library
       
      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 bytss_key. Although the same key value may be used by different threads, the values bound to the key bytss_set are maintained on a per-thread basis and persist for the life of the calling thread.

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

      Ifdestructor is not a null pointer, then also associates the destructor which is called when the storage is released bythrd_exit (but not bytss_delete and not at program termination byexit).

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

      Contents

      [edit]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

      [edit]Notes

      The POSIX equivalent of this function ispthread_key_create.

      [edit]Return value

      thrd_success if successful,thrd_error otherwise.

      [edit]Example

      This section is incomplete
      Reason: improve, perhaps look for POSIX examples for inspiration
      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

      [edit]References

      • C17 standard (ISO/IEC 9899:2018):
      • 7.26.6.1 The tss_create function (p: 281-282)
      • C11 standard (ISO/IEC 9899:2011):
      • 7.26.6.1 The tss_create function (p: 386)
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/thread/tss_create&oldid=138763"

      [8]ページ先頭

      ©2009-2025 Movatter.jp