ChibiOS 21.11.4
Dynamic Threads

Detailed Description

Dynamic threads related APIs and services.

Collaboration diagram for Dynamic Threads:

Functions

thread_tchThdCreateFromHeap (memory_heap_t *heapp, size_t size, const char *name, tprio_t prio, tfunc_t pf, void *arg)
 Creates a new thread allocating the memory from the heap.
thread_tchThdCreateFromMemoryPool (memory_pool_t *mp, const char *name, tprio_t prio, tfunc_t pf, void *arg)
 Creates a new thread allocating the memory from the specified memory pool.

Function Documentation

◆ chThdCreateFromHeap()

thread_t * chThdCreateFromHeap ( memory_heap_t * heapp,
size_t size,
const char * name,
tprio_t prio,
tfunc_t pf,
void * arg )

Creates a new thread allocating the memory from the heap.

Precondition
The configuration options CH_CFG_USE_DYNAMIC and CH_CFG_USE_HEAP must be enabled in order to use this function.
Note
A thread can terminate by calling chThdExit() or by simply returning from its main function.
The allocated thread memory is not released automatically, it is caller responsibility to call chThdRelease() or chThdWait() in order to release the allocated memory.
Parameters
[in]heappheap from which allocate the memory or NULL for the default heap
[in]sizesize of the working area to be allocated
[in]namethread name
[in]priothe priority level for the new thread
[in]pfthe thread function
[in]argan argument passed to the thread function. It can be NULL.
Returns
The pointer to the thread_t structure allocated for the thread into the working space area.
Return values
NULLif the memory cannot be allocated.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 82 of file chdynamic.c.

References __thd_stackfill(), CH_FLAG_MODE_HEAP, chHeapAllocAligned(), chSchWakeupS, chSysLock, chSysUnlock, chThdCreateSuspendedI(), ch_thread::flags, MSG_OK, PORT_WORKING_AREA_ALIGN, and THD_DESCRIPTOR.

Here is the call graph for this function:

◆ chThdCreateFromMemoryPool()

thread_t * chThdCreateFromMemoryPool ( memory_pool_t * mp,
const char * name,
tprio_t prio,
tfunc_t pf,
void * arg )

Creates a new thread allocating the memory from the specified memory pool.

Precondition
The configuration options CH_CFG_USE_DYNAMIC and CH_CFG_USE_MEMPOOLS must be enabled in order to use this function.
The pool must be initialized to contain only objects with alignment PORT_WORKING_AREA_ALIGN.
Note
A thread can terminate by calling chThdExit() or by simply returning from its main function.
The allocated thread memory is not released automatically, it is caller responsibility to call chThdRelease() or chThdWait() in order to release the allocated memory.
Parameters
[in]mppointer to the memory pool object
[in]namethread name
[in]priothe priority level for the new thread
[in]pfthe thread function
[in]argan argument passed to the thread function. It can be NULL.
Returns
The pointer to the thread_t structure allocated for the thread into the working space area.
Return values
NULLif the memory pool is empty.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 137 of file chdynamic.c.

References __thd_stackfill(), CH_FLAG_MODE_MPOOL, chDbgCheck, chPoolAlloc(), chSchWakeupS, chSysLock, chSysUnlock, chThdCreateSuspendedI(), ch_thread::flags, ch_thread::mpool, MSG_OK, memory_pool_t::object_size, and THD_DESCRIPTOR.

Here is the call graph for this function: