我要评分
获取效率
正确性
完整性
易理解

HTL_thread_create_from_pool

Creates a thread in a specified thread pool.

Interface Definition

int HTL_thread_create_from_pool(HTL_thread_pool_t thread_pool, HTL_thread_t *thread, const HTL_thread_attr_t *thread_attr, void *(*thread_func)(void *), void *thread_args);

Description

HTL_thread_create_from_pool() creates a new ULT whose attribute is specified by attr, associates it with the thread pool specified by thread_pool, and returns its handle through thread. This function places the created ULT into the thread pool thread_pool. When the ULT is scheduled, its parameter is transferred to the thread execution function thread_func().

attr can be created by HTL_thread_attr_create(). If attr is set to HTL_THREAD_ATTR_NULL, the default thread attribute is used. This function copies attr. Users can release attr after this function returns a value.

If thread is NULL, an unnamed ULT is created. The unnamed ULT is automatically released when thread_func() is completed. Otherwise, thread must be explicitly released by HTL_thread_free().

Parameters

Parameter

Type

Description

Input/Output

thread_pool

HTL_thread_pool_t *

Address of the handle to the thread pool.

Input

thread

HTL_thread_t *

Handle to the ULT.

Output

thread_attr

HTL_thread_attr_t *

ULT attribute.

Input

thread_func

void *(*thread_func)(void *)

New ULT execution function.

Input

thread_args

void *

Input parameter of thread_func.

Input

Return Value

  • HTL_THREAD_SUCCESS: success.
  • Other values: failure. For details, see the error code descriptions.

Example

1
2
3
4
5
6
    HTL_thread_pool_t *g_pools;
    vector_scal_task_args_t *arg;
    arg = (vector_scal_task_args_t *)args;
    for (i = arg->start; i < arg->end; i++) {
        HTL_thread_create_from_pool(g_pools[arg->id], NULL, HTL_THREAD_ATTR_NULL, task_function, (void *)&arg->ptr[i]);
    }