thrd_create
来自cppreference.com
在标头 <threads.h> 定义 | ||
int thrd_create( thrd_t *thr, thrd_start_t func, void *arg ); | (C11 起) | |
创建一个执行函数 func
的新线程,以 func(arg) 调用此函数。
若成功,则设置 thr
所指向的对象为新线程的标识符。
此函数的完成同步于线程的开始。
参数
thr | - | 指向放置新线程标识符的内存位置的指针 |
func | - | 要执行的函数 |
arg | - | 传递给函数的参数 |
返回值
若新线程创建成功则为 thrd_success。否则若内存不足则返回 thrd_nomem,若出现其他错误则返回 thrd_error
。
注意
一旦线程完结并融合或脱附,则可能重新使用线程标识符。
类型 thrd_start_t
是 int(*)(void*) 的 typedef,有别于 POSIX 的等价版本 void*(*)(void*)。
将所有所有线程特定存储值(见 tss_create)初始化为 NULL。
从函数 func
返回等价于以等于 func
返回值的参数调用 thrd_exit。
引用
- C17 标准(ISO/IEC 9899:2018):
- 7.26.5.1 The thrd_create function (第 279 页)
- C11 标准(ISO/IEC 9899:2011):
- 7.26.5.1 The thrd_create function (第 383 页)
参阅
(C11) | 分离线程 (函数) |
(C11) | 阻塞到线程终止为止 (函数) |
thread 的 C++ 文档 |