---
title: HTL_thread_create
description: "创建线程。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/2300/accel/kunpengaccel_ksl_16_0085.html
sourcePath: /source/zh/kunpengboostkithistory/2300/accel/kunpengaccel_ksl_16_0085.html
indexId: 728f48eec04a2ee862ca48ff1ef5b83149c0c843a54d08ee4dc56889c7b8498b74
---
# HTL_thread_create

创建线程。

#### 接口定义

int HTL_thread_create(HTL_thread_t *thread, const HTL_thread_attr_t *thread_attr, void *(*thread_func)(void *), void *thread_args);


#### 描述

HTL_thread_create()创建一个用户级线程ULT，并通过thread返回其句柄。HTL会自动将创建的ULT与一个线程池绑定，thread必须由HTL_thread_free()显式释放。

该函数仅适用于HTL-PThreads并行编程模式。


#### 参数

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| thread | HTL\_thread\_t \* | ULT句柄。 | 输出 |
| thread\_attr | HTL\_thread\_attr\_t \* | ULT的属性。 | 输入 |
| thread\_func | void\* (\*thread\_func)(void \*) | 新的ULT执行的函数。 | 输入 |
| thread\_args | void \* | thread\_func的入参。 | 输入 |


#### 返回值

- HTL_THREAD_SUCCESS：成功。
- 其他：失败。见错误码定义。


#### 示例

```
/* Create Thread */
for (i = 0; i < num_threads; i++) {
arg[i] = i;
ret = HTL_thread_create(&threads[i], NULL, thread_create, &arg[i]);
}
```
