thrd_create函数
概要:
#include <threads.h> int thrd_create(thrd_t *thr, thrd_start_t func, void *arg);
描述:
该函数创建一个执行func(arg)的新线程。如果新线程创建成功,函数将参数thr指向的对象设置为新线程的标识符。一旦原线程退出,并且原线程被分离或者连接到另一个线程,线程的标识符可以重新用于不同的线程。thrd_create函数创建新线程的完成与新线程的开始执行是同步的。
从func返回与使用func返回值调用thrd_exit函数具有相同的行为。
参数:
thrd_t *thr
指向新线程标识符的指针。
thrd_start_t func
指向新线程中执行函数的指针。
void *arg
指向传递给func函数参数的指针。
返回值:
如果成功创建新线程,函数返回thrd_success;如果不能分配新线程请求的内存,函数返回thrd_nomem;如果无法创建新线程,函数返回thrd_error。
范例:
|
|
输出:
The new thread has been created successfully.
This is a new thread.
注:使用Pelles C编译。
相关内容:
thrd_current | 标识调用线程的函数。 |
thrd_detach | 分离线程的函数。 |
thrd_equal | 测试两个线程是否为同一线程的函数。 |
thrd_exit | 终止当前线程的函数。 |
thrd_join | 连接线程的函数。 |
thrd_sleep | 暂停当前线程的函数。 |
thrd_yield | 让其它线程运行的函数。 |