pub unsafe extern "C" fn k_thread_create(
new_thread: *mut k_thread,
stack: *mut z_thread_stack_element,
stack_size: usize,
entry: Option<unsafe extern "C" fn(_: *mut c_void, _: *mut c_void, _: *mut c_void)>,
p1: *mut c_void,
p2: *mut c_void,
p3: *mut c_void,
prio: i32,
options: u32,
delay: k_timeout_t,
) -> *mut k_thread
Expand description
@brief Create a thread.
This routine initializes a thread, then schedules it for execution.
The new thread may be scheduled for immediate execution or a delayed start. If the newly spawned thread does not have a delayed start the kernel scheduler may preempt the current thread to allow the new thread to execute.
Thread options are architecture-specific, and can include K_ESSENTIAL, K_FP_REGS, and K_SSE_REGS. Multiple options may be specified by separating them using “|” (the logical OR operator).
Stack objects passed to this function must be originally defined with either of these macros in order to be portable:
- K_THREAD_STACK_DEFINE() - For stacks that may support either user or supervisor threads.
- K_KERNEL_STACK_DEFINE() - For stacks that may support supervisor threads only. These stacks use less memory if CONFIG_USERSPACE is enabled.
The stack_size parameter has constraints. It must either be:
- The original size value passed to K_THREAD_STACK_DEFINE() or K_KERNEL_STACK_DEFINE()
- The return value of K_THREAD_STACK_SIZEOF(stack) if the stack was defined with K_THREAD_STACK_DEFINE()
- The return value of K_KERNEL_STACK_SIZEOF(stack) if the stack was defined with K_KERNEL_STACK_DEFINE().
Using other values, or sizeof(stack) may produce undefined behavior.
@param new_thread Pointer to uninitialized struct k_thread @param stack Pointer to the stack space. @param stack_size Stack size in bytes. @param entry Thread entry function. @param p1 1st entry point parameter. @param p2 2nd entry point parameter. @param p3 3rd entry point parameter. @param prio Thread priority. @param options Thread options. @param delay Scheduling delay, or K_NO_WAIT (for no delay).
@return ID of new thread.