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