Function k_thread_stack_alloc

Source
pub unsafe extern "C" fn k_thread_stack_alloc(
    size: usize,
    flags: i32,
) -> *mut z_thread_stack_element
Expand description

@brief Dynamically allocate a thread stack.

Dynamically allocate a thread stack either from a pool of thread stacks of size @kconfig{CONFIG_DYNAMIC_THREAD_POOL_SIZE}, or from the system heap. Order is determined by the @kconfig{CONFIG_DYNAMIC_THREAD_PREFER_ALLOC} and @kconfig{CONFIG_DYNAMIC_THREAD_PREFER_POOL} options. Thread stacks from the pool are of maximum size @kconfig{CONFIG_DYNAMIC_THREAD_STACK_SIZE}.

@note When no longer required, thread stacks allocated with k_thread_stack_alloc() must be freed with @ref k_thread_stack_free to avoid leaking memory.

@param size Stack size in bytes. @param flags Stack creation flags, or 0.

@retval the allocated thread stack on success. @retval NULL on failure.

Relevant stack creation flags include:

  • @ref K_USER allocate a userspace thread (requires @kconfig{CONFIG_USERSPACE})

@see @kconfig{CONFIG_DYNAMIC_THREAD}