標準庫標頭檔案 <threads.h> (C11)
來自 cppreference.com
此標頭檔案是併發支援庫的一部分,提供對執行緒、互斥、條件變數和執行緒區域性儲存的支援。
目錄 |
[編輯] 執行緒
thrd_t
|
識別執行緒的、由實現定義的完整物件型別 |
(C11) |
建立執行緒 (函式) |
(C11) |
檢查兩個識別符號是否指向同一個執行緒 (函式) |
(C11) |
獲取當前執行緒識別符號 (函式) |
(C11) |
暫停呼叫執行緒的執行指定時間 (函式) |
(C11) |
讓出當前時間片 (函式) |
(C11) |
終止呼叫執行緒 (函式) |
(C11) |
分離執行緒 (函式) |
(C11) |
阻塞直到執行緒終止 (函式) |
指示執行緒錯誤狀態 (常量) | |
thrd_start_t (C11) |
函式指標型別 int(*)(void*) 的型別定義,用於 thrd_create (型別定義) |
[編輯] 互斥
mtx_t
|
互斥量識別符號 |
(C11) |
建立互斥體 (函式) |
(C11) |
阻塞直到鎖定互斥體 (函式) |
(C11) |
阻塞直到鎖定互斥體或超時 (函式) |
(C11) |
鎖定互斥體,如果已鎖定則不阻塞返回 (函式) |
(C11) |
解鎖互斥體 (函式) |
(C11) |
銷燬互斥量 (函式) |
(C11)(C11)(C11) |
定義互斥量型別 (列舉) |
一次呼叫 | |
(C11) |
只調用函式一次 (函式) |
[編輯] 條件變數
cnd_t
|
條件變數識別符號 |
(C11) |
建立條件變數 (函式) |
(C11) |
解除阻塞在條件變數上阻塞的一個執行緒 (函式) |
(C11) |
解除阻塞在條件變數上阻塞的所有執行緒 (函式) |
(C11) |
在條件變數上阻塞 (函式) |
(C11) |
在條件變數上阻塞,帶有超時 (函式) |
(C11) |
銷燬條件變數 (函式) |
[編輯] 執行緒區域性儲存
(C11 起)(C23 中移除) |
儲存類說明符 _Thread_local 的便捷宏 (關鍵字宏) |
tss_t
|
執行緒區域性儲存指標 |
(C11) |
解構函式呼叫的最大次數 (宏常量) |
tss_dtor_t (C11) |
函式指標型別 void(*)(void*),用於 TSS 解構函式 (型別定義) |
(C11) |
建立帶有給定解構函式的執行緒區域性儲存指標 (函式) |
(C11) |
從執行緒區域性儲存讀取 (函式) |
(C11) |
寫入執行緒區域性儲存 (函式) |
(C11) |
釋放給定執行緒區域性指標所持有的資源 (函式) |
[編輯] 概要
#define __STDC_NO_THREADS__ 202311L #define ONCE_FLAG_INIT /* see description */ #define TSS_DTOR_ITERATIONS /* see description */ typedef /* see description */ cnd_t; typedef /* see description */ thrd_t; typedef /* see description */ tss_t; typedef /* see description */ mtx_t; typedef /* see description */ tss_dtor_t; typedef /* see description */ thrd_start_t; #define mtx_plain /* see description */ #define mtx_recursive /* see description */ #define mtx_timed /* see description */ #define once_flag /* see description */ #define thrd_busy /* see description */ #define thrd_error /* see description */ #define thrd_nomem /* see description */ #define thrd_success /* see description */ #define thrd_timedout /* see description */ void call_once(once_flag* flag, void (*func)(void)); int cnd_broadcast(cnd_t* cond); void cnd_destroy(cnd_t* cond); int cnd_init(cnd_t* cond); int cnd_signal(cnd_t* cond); int cnd_timedwait(cnd_t* restrict cond, mtx_t* restrict mtx, const struct timespec* restrict ts); int cnd_wait(cnd_t* cond, mtx_t* mtx); void mtx_destroy(mtx_t* mtx); int mtx_init(mtx_t* mtx, int type); int mtx_lock(mtx_t* mtx); int mtx_timedlock(mtx_t* restrict mtx, const struct timespec* restrict ts); int mtx_trylock(mtx_t* mtx); int mtx_unlock(mtx_t* mtx); int thrd_create(thrd_t* thr, thrd_start_t func, void* arg); thrd_t thrd_current(void); int thrd_detach(thrd_t thr); int thrd_equal(thrd_t thr0, thrd_t thr1); [[noreturn]] void thrd_exit(int res); int thrd_join(thrd_t thr, int* res); int thrd_sleep(const struct timespec* duration, struct timespec* remaining); void thrd_yield(void); int tss_create(tss_t* key, tss_dtor_t dtor); void tss_delete(tss_t key); void* tss_get(tss_t key); int tss_set(tss_t key, void* val);