?
This document uses PHP Chinese website manual Release
在頭文件<threads.h>中定義 | ||
---|---|---|
int tss_set(tss_t tss_id,void * val); | (自C11以來) |
將當前線程的tss_id標識的線程專有存儲的值設置為val。 不同的線程可以為同一個鍵設置不同的值。
析構函數(shù)如果可用,則不會被調用。
tss_id | - | 線程特定的存儲密鑰,從tss_create獲取,不被tss_delete刪除 |
---|---|---|
val | - | 設置線程專有存儲的值 |
如果成功則返回thrd_success,否則返回thrd_error。
這個函數(shù)的POSIX等價物是pthread_setspecific。
通常,TSS用于存儲指向已被保留供調用線程使用的動態(tài)分配內存塊的指針。
可以在TSS析構函數(shù)中調用tss_set。 如果析構函數(shù)在TSS存儲中以非NULL值退出,它將被thrd_exit重試直到TSS_DTOR_ITERATIONS次,之后存儲將會丟失。
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
C11標準(ISO / IEC 9899:2011):
7.26.6.4 tss_set 函數(shù)(p:387)
tss_get(C11) | 從線程專有存儲器讀?。üδ埽?/p> |
---|