---
title: HTL_thread_setspecific
description: "设置线程私有变量的值。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/2300/accel/kunpengaccel_ksl_16_0098.html
sourcePath: /source/zh/kunpengboostkithistory/2300/accel/kunpengaccel_ksl_16_0098.html
indexId: 7754fbf2d4684e7b0199ca7cc8714e7305826696f0e7bc844cf1cd2a5375c9a074
---
# HTL_thread_setspecific

设置线程私有变量的值。

#### 接口定义

int HTL_thread_setspecific(HTL_thread_key_t thread_key, const void *value);


#### 描述

HTL_thread_setspecific()用于在线程中将线程私有变量thread_key与值value进行关联。不用的线程可使用相同的线程私有变量绑定不同的值。


#### 参数

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| thread\_key | HTL\_thread\_key\_t | 线程私有变量句柄。 | 输入 |
| value | void \* | 值。 | 输入 |


#### 返回值

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


#### 示例

```
static HTL_thread_key_t tls[NUM_TLS];
int j;
ret = HTL_thread_setspecific(tls[j], (void *)(intptr_t)j);
```
