Namespaces
Variants

Standard library header <threads.h> (C11)

From cppreference.net

此头文件属于 并发支持库 的一部分,提供对线程、互斥锁、条件变量和线程局部存储的支持。

目录

线程

thrd_t 实现定义的完整对象类型,用于标识线程
创建线程
(函数)
检查两个标识符是否引用同一线程
(函数)
获取当前线程标识符
(函数)
暂停调用线程执行指定时长
(函数)
让出当前时间片
(函数)
终止调用线程
(函数)
分离线程
(函数)
阻塞直至线程终止
(函数)
指示线程错误状态
(常量)
thrd_start_t
(C11)
函数指针类型 int ( * ) ( void * ) 的类型定义,由 thrd_create 使用
(类型定义)

互斥锁

mtx_t 互斥锁标识符
创建互斥锁
(函数)
阻塞直至锁定互斥锁
(函数)
阻塞直至锁定互斥锁或超时
(函数)
锁定互斥锁,若已被锁定则立即返回而不阻塞
(函数)
解锁互斥锁
(函数)
销毁互斥锁
(函数)
定义互斥锁类型
(枚举)
一次性调用
精确调用函数一次
(函数)

条件变量

cnd_t 条件变量标识符
创建条件变量
(函数)
解除阻塞在条件变量上的一个线程
(函数)
解除阻塞在条件变量上的所有线程
(函数)
在条件变量上阻塞
(函数)
在条件变量上阻塞,带超时
(函数)
销毁条件变量
(函数)

线程局部存储

(C11) (removed in C23)
存储类说明符 _Thread_local 的便捷宏
(关键字宏)
tss_t 线程特定存储指针
析构函数最大调用次数
(宏常量)
tss_dtor_t
(C11)
函数指针类型 void ( * ) ( void * ) ,用于 TSS 析构函数
(类型定义)
创建带有指定析构函数的线程特定存储指针
(函数)
(C11)
从线程特定存储读取数据
(函数)
(C11)
向线程特定存储写入数据
(函数)
释放指定线程特定指针持有的资源
(函数)

概要

#define __STDC_NO_THREADS__ 202311L
#define ONCE_FLAG_INIT      /* 详见描述 */
#define TSS_DTOR_ITERATIONS /* 详见描述 */
typedef /* 详见描述 */ cnd_t;
typedef /* 详见描述 */ thrd_t;
typedef /* 详见描述 */ tss_t;
typedef /* 详见描述 */ mtx_t;
typedef /* 详见描述 */ tss_dtor_t;
typedef /* 详见描述 */ thrd_start_t;
#define mtx_plain     /* 详见描述 */
#define mtx_recursive /* 详见描述 */
#define mtx_timed     /* 详见描述 */
#define once_flag     /* 详见描述 */
#define thrd_busy     /* 详见描述 */
#define thrd_error    /* 详见描述 */
#define thrd_nomem    /* 详见描述 */
#define thrd_success  /* 详见描述 */
#define thrd_timedout /* 详见描述 */
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);