threads.h 文件

用途

threads.h 头文件包含 time.h 头文件并定义宏它还声明支持多个执行线程的类型,枚举常量和函数。

描述

threads.h 头文件不得由定义宏 _ _STDC_NO_THREADS_ _ 的实现提供。此外,此类实现不得支持由头 threads.h 文件指定的任何工具。

threads.h 头文件声明以下宏:
线程局部变量
展开为 _Thread_local
ONCE_FLAG_INIT
展开为可用于初始化类型为 once_flag的对象的值。
TSS_DTOR_迭代次数
扩展为表示线程终止时调用析构函数的最大次数的整数常量表达式。
threads.h 头文件声明以下类型:
计数
保存条件变量的标识的完整对象类型。
特雷特
保存线程标识的完整对象类型。
Tss_t
保存特定于线程的存储指针的标识的完整对象类型。
mtx_t
保存互斥对象的标识的完整对象类型。
Tss_dtor_t
函数指针类型 void (*) (void *),用于特定于线程的存储指针的析构函数。
已启动
传递到 thrd_create 以创建新线程的函数指针类型 int (*) (void *)。
once_flag
保存供 call_once使用的标志的完整对象类型。
threads.h 头文件声明以下枚举常量:
mtx_plain
mtx_plain 类型将传递到 mtx_init 以创建不支持超时的互斥对象并测试和返回。
mtx_递归
mtx_recursive 类型传递到 mtx_init 以创建支持递归锁定的互斥对象。
mtx_定时
mtx_timed 类型将传递到 mtx_init 以创建支持超时的互斥对象。
惊险刺激
cnd_t 类型由定时等待函数返回,以指示在未获取请求的资源的情况下达到调用中指定的时间。
成功
thrd_success 类型由函数返回,以指示请求的操作成功。
已忙碌
thrd_busy 类型由函数返回,以指示所请求的操作失败,因为测试和返回函数所请求的资源已在使用中。
系统错误
thrd_error 类型由函数返回,以指示请求的操作失败。
特拉斯-诺姆
thrd_nomem 类型由函数返回,以指示请求的操作由于无法分配内存而失败。
threads.h 头文件声明以下函数:
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);