命名空间
变体
操作

标准库头文件 <threads.h> (C11)

来自 cppreference.cn
< c‎ | 头文件

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

目录

[编辑] 线程

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

[编辑] 互斥

mtx_t 互斥量标识符[编辑]
创建互斥体
(函数) [编辑]
阻塞直到锁定互斥体
(函数) [编辑]
阻塞直到锁定互斥体或超时
(函数) [编辑]
锁定互斥体,如果已锁定则不阻塞返回
(函数) [编辑]
解锁互斥体
(函数) [编辑]
销毁互斥量
(函数) [编辑]
定义互斥量类型
(枚举) [编辑]
一次调用
只调用函数一次
(函数) [编辑]

[编辑] 条件变量

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

[编辑] 线程局部存储

(C11 起)(C23 中移除)
存储类说明符 _Thread_local 的便捷宏
(关键字宏) [编辑]
tss_t 线程局部存储指针[编辑]
析构函数调用的最大次数
(宏常量) [编辑]
tss_dtor_t
(C11)
函数指针类型 void(*)(void*),用于 TSS 析构函数
(类型定义) [编辑]
创建带有给定析构函数的线程局部存储指针
(函数) [编辑]
从线程局部存储读取
(函数) [编辑]
写入线程局部存储
(函数) [编辑]
释放给定线程局部指针所持有的资源
(函数) [编辑]

[编辑] 概要

#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);