Rate This Document
Findability
Accuracy
Completeness
Readability

HTL_thread_attr_setstack

Specifies memory and sets the stack size in the thread attribute.

Interface Definition

int HTL_thread_attr_setstack(HTL_thread_attr_t *thread_attr, void *stackaddr, size_t stacksize);

Description

HTL_thread_attr_setstack() sets the stack address (stackaddr) and stack size (stacksize, in bytes) in thread_attr.

The memory pointed to by stackaddr will be used as the stack area of the created thread.

  • If stackaddr is NULL:

    When a thread is created, HTL automatically allocates a stack whose size is stacksize. The stack is automatically released when HTL is running.

  • If stackaddr is not NULL:

    The value of stackaddr must be 8-byte-aligned. Users need to release the memory after using it.

It is not recommended that multiple threads share the same stack memory because the function stack may be damaged and the program may crash.

Parameters

Parameter

Type

Description

Input/Output

thread_attr

HTL_thread_attr_t *

Address of the handle to the thread attribute.

Input

stackaddr

void *

Stack address.

Input

stacksize

size_t

Stack size, in bytes.

Input

Return Value

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

Example

    const size_t stacksize = 32768;
    stack = malloc(stacksize);
    HTL_thread_attr_t attr;
    ret = HTL_thread_attr_init(&attr);
    ret = HTL_thread_attr_setstack(&attr, stack, stacksize);