Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      tss_set

      From cppreference.com
      <c‎ |thread
       
       
      Concurrency support library
       
      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 bytss_id for the current thread toval. Different threads may set different values to the same key.

      The destructor, if available, is not invoked.

      Contents

      [edit]Parameters

      tss_id - thread-specific storage key, obtained fromtss_create and not deleted bytss_delete
      val - value to set thread-specific storage to

      [edit]Return value

      thrd_success if successful,thrd_error otherwise.

      [edit]Notes

      The POSIX equivalent of this function ispthread_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 bythrd_exit up toTSS_DTOR_ITERATIONS times, after which the storage will be lost.

      [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.4 The tss_set function (p: 282-283)
      • C11 standard (ISO/IEC 9899:2011):
      • 7.26.6.4 The tss_set function (p: 387)

      [edit]See also

      (C11)
      reads from thread-specific storage
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/thread/tss_set&oldid=138762"

      [8]ページ先頭

      ©2009-2025 Movatter.jp