HTL_thread_key_create
Creates a thread private variable.
Interface Definition
int HTL_thread_key_create(void (*destructor)(void *value), HTL_thread_key_t *thread_key);
Description
HTL_thread_key_create() is used to create a thread private variable thread_key of the HTL_thread_key_t type. Although different threads can use the same thread private variable thread_key, the value of thread_key set through HTL_thread_setspecific() varies by thread.
When a thread private variable is created, the NULL value is associated with the new thread private variable thread_key in all existing threads. When a new thread is created, the NULL value is associated with all defined thread private variables in the new thread.
The destructor function destructor() is optional and is registered with the thread private variable thread_key. When a thread exits, this function is automatically called if the thread private variable is not NULL.
The created thread private variable thread_key must be released by HTL_thread_key_delete() after being used.
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
destructor |
void (*destructor)(void *value) |
Destructor. |
Input |
thread_key |
HTL_thread_key_t * |
Address of the handle to the thread private variable. |
Output |
Return Value
- HTL_THREAD_SUCCESS: success.
- Other values: failure. For details, see the error code descriptions.
Example
int ret;
static HTL_thread_key_t tls[NUM_TLS];
ret = HTL_thread_key_create(NULL, &tls[i]);