1 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2 // ==== Thread Management ====
4 \addtogroup CMSIS_RTOS_ThreadMgmt Thread Management
5 \ingroup CMSIS_RTOS CMSIS_RTOSv2
6 \brief Define, create, and control thread functions.
8 The Thread Management function group allows defining, creating, and controlling thread functions in the system.
10 \note Thread management functions cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
15 Threads can be in the following states:
17 - \b RUNNING: The thread that is currently running is in the \ref ThreadStates "RUNNING" state. Only one thread at a time can be in this
19 - \b READY: Threads which are ready to run are in the \ref ThreadStates "READY" state. Once the \ref ThreadStates "RUNNING" thread has terminated, or is
20 \ref ThreadStates "BLOCKED", the next \ref ThreadStates "READY" thread with the highest priority becomes the \ref ThreadStates "RUNNING" thread.
21 - \b BLOCKED: Threads that are blocked either delayed, waiting for an event to occur or suspended are in the \ref ThreadStates "BLOCKED"
23 - \b TERMINATED: When \ref osThreadTerminate is called, threads are \ref ThreadStates "TERMINATED" with resources not yet released.
24 - \b INACTIVE: Threads that are not created or have been terminated with all resources released are in the \ref ThreadStates "INACTIVE" state.
26 \image html "ThreadStatus.png" "Thread State and State Transitions"
29 A CMSIS-RTOS assumes that threads are scheduled as shown in the figure <b>Thread State and State Transitions</b>. The thread
30 states change as follows:
31 - A thread is created using the function \ref osThreadNew. This puts the thread into the \ref ThreadStates "READY" or \ref ThreadStates "RUNNING" state
32 (depending on the thread priority).
33 - CMSIS-RTOS is pre-emptive. The active thread with the highest priority becomes the \ref ThreadStates "RUNNING" thread provided it does not
34 wait for any event. The initial priority of a thread is defined with the \ref osThreadAttr_t but may be changed during
35 execution using the function \ref osThreadSetPriority.
36 - The \ref ThreadStates "RUNNING" thread transfers into the \ref ThreadStates "BLOCKED" state when it is delayed, waiting for an event or suspended.
37 - Active threads can be terminated any time using the function \ref osThreadTerminate. Threads can terminate also by just
38 returning from the thread function. Threads that are terminated are in the \ref ThreadStates "INACTIVE" state and typically do not consume
39 any dynamic memory resources.
42 Refer to \ref threadConfig for RTX5 configuration options.
44 \anchor thread_examples
47 The following examples show various scenarios to create threads:
49 <b>Example 1 - Create a simple thread</b>
51 Create a thread out of the function thread1 using all default values for thread attributes and memory from the
52 \ref GlobalMemoryPool.
55 __NO_RETURN void thread1 (void *argument) {
63 osThreadNew(thread1, NULL, NULL); // Create thread with default settings
69 <b>Example 2 - Create thread with stack non-default stack size</b>
71 Similar to the simple thread all attributes are default. The stack is dynamically allocated from the \ref GlobalMemoryPool
73 \ref osThreadAttr_t.stack_size is used to pass the stack size in Bytes to osThreadNew.
76 __NO_RETURN void thread1 (void *argument) {
81 const osThreadAttr_t thread1_attr = {
82 .stack_size = 1024 // Create the thread stack with a size of 1024 bytes
87 osThreadNew(thread1, NULL, &thread1_attr); // Create thread with custom sized stack memory
92 <b>Example 3 - Create thread with statically allocated stack</b>
94 Similar to the simple thread all attributes are default. The stack is statically allocated using the \c uint64_t array
95 \c thread1_stk_1. This allocates 64*8 Bytes (=512 Bytes) with an alignment of 8 Bytes (mandatory for Cortex-M stack memory).
97 \ref osThreadAttr_t.stack_mem holds a pointer to the stacks lowest address.
99 \ref osThreadAttr_t.stack_size is used to pass the stack size in Bytes to osThreadNew.
102 __NO_RETURN void thread1 (void *argument) {
107 static uint64_t thread1_stk_1[64];
109 const osThreadAttr_t thread1_attr = {
110 .stack_mem = &thread1_stk_1[0],
111 .stack_size = sizeof(thread1_stk_1)
116 osThreadNew(thread1, NULL, &thread1_attr); // Create thread with statically allocated stack memory
121 <b>Example 4 - Thread with statically allocated task control block</b>
123 Typically this method is chosen together with a statically allocated stack as shown in Example 2.
125 #include "cmsis_os2.h"
127 //include rtx_os.h for types of RTX objects
130 __NO_RETURN void thread1 (void *argument) {
135 static osRtxThread_t thread1_tcb;
137 const osThreadAttr_t thread1_attr = {
138 .cb_mem = &thread1_tcb,
139 .cb_size = sizeof(thread1_tcb),
144 osThreadNew(thread1, NULL, &thread1_attr); // Create thread with custom tcb memory
149 <b>Example 5 - Create thread with a different priority</b>
151 The default priority of RTX is \ref osPriorityNormal. Often you want to run a task with a higher or lower priority. Using the
152 \ref osThreadAttr_t control structure you can set any initial priority required.
155 __NO_RETURN void thread1 (void *argument) {
160 const osThreadAttr_t thread1_attr = {
161 .priority = osPriorityHigh //Set initial thread priority to high
166 osThreadNew(thread1, NULL, &thread1_attr);
171 <b>Example 6 - Joinable threads</b>
173 In this example a master thread creates four threads with the \ref osThreadJoinable attribute. These will do some work and
174 return using the \ref osThreadExit call after finished. \ref osThreadJoin is used to synchronize the thread termination.
178 __NO_RETURN void worker (void *argument) {
179 ; // work a lot on data[]
184 __NO_RETURN void thread1 (void *argument) {
185 osThreadAttr_t worker_attr;
186 osThreadId_t worker_ids[4];
189 memset(&worker_attr, 0, sizeof(worker_attr));
190 worker_attr.attr_bits = osThreadJoinable;
192 worker_ids[0] = osThreadNew(worker, &data[0][0], &worker_attr);
193 worker_ids[1] = osThreadNew(worker, &data[1][0], &worker_attr);
194 worker_ids[2] = osThreadNew(worker, &data[2][0], &worker_attr);
195 worker_ids[3] = osThreadNew(worker, &data[3][0], &worker_attr);
197 osThreadJoin(worker_ids[0]);
198 osThreadJoin(worker_ids[1]);
199 osThreadJoin(worker_ids[2]);
200 osThreadJoin(worker_ids[3]);
208 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
210 \enum osThreadState_t
212 State of a thread as retrieved by \ref osThreadGetState. In case \b osThreadGetState fails or if it is called from an ISR, it
213 will return \c osThreadError, otherwise it returns the thread state.
215 \var osThreadState_t::osThreadInactive
216 \details The thread is created but not actively used, or has been terminated.
218 \var osThreadState_t::osThreadReady
219 \details The thread is ready for execution but not currently running.
221 \var osThreadState_t::osThreadRunning
222 \details The thread is currently running.
224 \var osThreadState_t::osThreadBlocked
225 \details The thread is currently blocked (delayed, waiting for an event or suspended).
227 \var osThreadState_t::osThreadTerminated
228 \details The thread is terminated and all its resources are freed.
230 \var osThreadState_t::osThreadError
231 \details The thread thread has raised an error condition and cannot be scheduled.
234 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
239 The \b osPriority_t value specifies the priority for a thread. The default thread priority should be \a osPriorityNormal.
240 If an active thread becomes ready that has a higher priority than the currently running thread then a thread switch occurs
241 immediately. The system continues executing the thread with the higher priority.
243 To prevent from a priority inversion, a CMSIS-RTOS compliant OS may optionally implement a <b>priority inheritance</b>
244 method. A priority inversion occurs when a high priority thread is waiting for a resource or event that is controlled by a
245 thread with a lower priority. Thus causing the high priority thread potentially beeing blocked forever by another thread
246 with lower priority. To come over this issue the low priority thread controlling the resource should be treated as having
247 the higher priority until it releases the resource.
249 \note Priority inheritance only applies to mutexes.
251 \var osPriority_t::osPriorityIdle
252 \details This lowest priority should not be used for any other thread.
254 \var osPriority_t::osPriorityISR
255 \details This highest priority might be used by the RTOS implementation but must not be used for any user thread.
258 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
260 \typedef void (*osThreadFunc_t) (void *argument)
261 \details Entry function for threads. Setting up a new thread (\ref osThreadNew) will start execution with a call into this
262 entry function. The optional argument can be used to hand over arbitrary user data to the thread, i.e. to identify the thread
263 or for runtime parameters.
265 \param[in] argument Arbitrary user data set on \ref osThreadNew.
268 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
270 \typedef osThreadId_t
271 \details Returned by:
274 - \ref osThreadEnumerate
275 - \ref osMutexGetOwner
278 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
280 \struct osThreadAttr_t
283 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
285 \def osThreadJoinable
287 A thread in this state can be joined using \ref osThreadJoin.
291 \def osThreadDetached
293 A thread in this state cannot be joined using \ref osThreadJoin.
296 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
298 \fn osThreadId_t osThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr)
300 The function \b osThreadNew starts a thread function by adding it to the list of active threads and sets it to state
301 \ref ThreadStates "READY". Arguments for the thread function are passed using the parameter pointer \a *argument. When the priority of the
302 created thread function is higher than the current \ref ThreadStates "RUNNING" thread, the created thread function starts instantly and
303 becomes the new \ref ThreadStates "RUNNING" thread. Thread attributes are defined with the parameter pointer \a attr. Attributes include
304 settings for thread priority, stack size, or memory allocation.
306 The function can be safely called before the RTOS is
307 started (call to \ref osKernelStart), but not before it is initialized (call to \ref osKernelInitialize).
309 The function \b osThreadNew returns the pointer to the thread object identifier or \token{NULL} in case of an error.
311 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
315 Refer to the \ref thread_examples "Thread Examples" section.
318 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
320 \fn const char *osThreadGetName (osThreadId_t thread_id)
322 The function \b osThreadGetName returns the pointer to the name string of the thread identified by parameter \a thread_id or
323 \token{NULL} in case of an error.
325 \note This function \b cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
329 void ThreadGetName_example (void) {
330 const char* name = osThreadGetName ();
332 // Failed to get the thread name; not in a thread
338 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
340 \fn osThreadId_t osThreadGetId (void)
342 The function \b osThreadGetId returns the thread object ID of the currently running thread or NULL in case of an error.
344 \note This function \b cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
348 void ThreadGetId_example (void) {
349 osThreadId_t id; // id for the currently running thread
351 id = osThreadGetId ();
353 // Failed to get the id; not in a thread
358 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
360 \fn osThreadState_t osThreadGetState (osThreadId_t thread_id)
362 The function \b osThreadGetState returns the state of the thread identified by parameter \a thread_id. In case it fails or
363 if it is called from an ISR, it will return \c osThreadError, otherwise it returns the thread state (refer to
364 \ref osThreadState_t for the list of thread states).
366 \note This function \b cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
369 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
371 \fn osStatus_t osThreadSetPriority (osThreadId_t thread_id, osPriority_t priority)
373 The function \b osThreadSetPriority changes the priority of an active thread specified by the parameter \a thread_id to the
374 priority specified by the parameter \a priority.
376 Possible \ref osStatus_t return values:
377 - \em osOK: the priority of the specified thread has been changed successfully.
378 - \em osErrorParameter: \a thread_id is \token{NULL} or invalid or \a priority is incorrect.
379 - \em osErrorResource: thread specified by parameter \em thread_id is in an invalid thread state.
380 - \em osErrorISR: the function \b osThreadSetPriority cannot be called from interrupt service routines.
382 \note This function \b cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
386 #include "cmsis_os2.h"
388 void Thread_1 (void const *arg) { // Thread function
389 osThreadId_t id; // id for the currently running thread
390 osStatus_t status; // status of the executed function
393 id = osThreadGetId (); // Obtain ID of current running thread
395 status = osThreadSetPriority (id, osPriorityBelowNormal); // Set thread priority
396 if (status == osOK) {
397 // Thread priority changed to BelowNormal
400 // Failed to set the priority
406 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
408 \fn osPriority_t osThreadGetPriority (osThreadId_t thread_id)
410 The function \b osThreadGetPriority returns the priority of an active thread specified by the parameter \a thread_id.
412 Possible \ref osPriority_t return values:
413 - \em priority: the priority of the specified thread.
414 - \em osPriorityError: priority cannot be determined or is illegal. It is also returned when the function is called from
415 \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
417 \note This function \b cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
421 #include "cmsis_os2.h"
423 void Thread_1 (void const *arg) { // Thread function
424 osThreadId_t id; // id for the currently running thread
425 osPriority_t priority; // thread priority
427 id = osThreadGetId (); // Obtain ID of current running thread
428 priority = osThreadGetPriority (id); // Obtain the thread priority
432 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
434 \fn osStatus_t osThreadYield (void)
436 The function \b osThreadYield passes control to the next thread with the same priority that is in the \ref ThreadStates "READY" state.
437 If there is no other thread with the same priority in state \ref ThreadStates "READY", then the current thread continues execution and
438 no thread switch occurs. \b osThreadYield does not set the thread to state \ref ThreadStates "BLOCKED". Thus no thread with a lower
439 priority will be scheduled even if threads in state \ref ThreadStates "READY" are available.
441 Possible \ref osStatus_t return values:
442 - \em osOK: control has been passed to the next thread successfully.
443 - \em osError: an unspecified error has occurred.
444 - \em osErrorISR: the function \b osThreadYield cannot be called from interrupt service routines.
446 \note This function \b cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
447 \note This function <b>has no impact</b> when called when the kernel is locked, see \ref osKernelLock.
451 #include "cmsis_os2.h"
453 void Thread_1 (void const *arg) { // Thread function
454 osStatus_t status; // status of the executed function
457 status = osThreadYield(); //
458 if (status != osOK) {
465 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
467 \fn osStatus_t osThreadSuspend (osThreadId_t thread_id)
469 The function \b osThreadSuspend suspends the execution of the thread identified by parameter \em thread_id. The thread is put
470 into the \ref ThreadStates "BLOCKED" state (\ref osThreadBlocked). Suspending the running thread will cause a context switch to another
471 thread in \ref ThreadStates "READY" state immediately. The suspended thread is not executed until explicitly resumed with the function \ref osThreadResume.
473 Threads that are already \ref ThreadStates "BLOCKED" are removed from any wait list and become ready when they are resumed.
474 Thus it is not recommended to suspend an already blocked thread.
476 Possible \ref osStatus_t return values:
477 - \em osOK: the thread has been suspended successfully.
478 - \em osErrorParameter: \a thread_id is \token{NULL} or invalid.
479 - \em osErrorResource: thread specified by parameter \em thread_id is in an invalid thread state.
480 - \em osErrorISR: the function \b osThreadSuspend cannot be called from interrupt service routines.
482 \note This function \b cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
483 \note This function <b>must not</b> be called to suspend the running thread when the kernel is locked, i.e. \ref osKernelLock.
487 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
489 \fn osStatus_t osThreadResume (osThreadId_t thread_id)
491 The function \b osThreadResume puts the thread identified by parameter \em thread_id (which has to be in \ref ThreadStates "BLOCKED" state)
492 back to the \ref ThreadStates "READY" state. If the resumed thread has a higher priority than the running thread a context switch occurs immediately.
494 The thread becomes ready regardless of the reason why the thread was blocked. Thus it is not recommended to resume a thread not suspended
495 by \ref osThreadSuspend.
497 Functions that will put a thread into \ref ThreadStates "BLOCKED" state are:
498 \ref osEventFlagsWait and \ref osThreadFlagsWait,
499 \ref osDelay and \ref osDelayUntil,
500 \ref osMutexAcquire and \ref osSemaphoreAcquire,
501 \ref osMessageQueueGet,
502 \ref osMemoryPoolAlloc,
504 \ref osThreadSuspend.
506 Possible \ref osStatus_t return values:
507 - \em osOK: the thread has been resumed successfully.
508 - \em osErrorParameter: \a thread_id is \token{NULL} or invalid.
509 - \em osErrorResource: thread specified by parameter \em thread_id is in an invalid thread state.
510 - \em osErrorISR: the function \b osThreadResume cannot be called from interrupt service routines.
512 \note This function \b cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
513 \note This function <b>may be</b> called when kernel is locked (\ref osKernelLock). Under this circumstances
514 a potential context switch is delayed until the kernel gets unlocked, i.e. \ref osKernelUnlock or \ref osKernelRestoreLock.
518 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
520 \fn osStatus_t osThreadDetach (osThreadId_t thread_id)
522 The function \b osThreadDetach changes the attribute of a thread (specified by \em thread_id) to \ref osThreadDetached.
523 Detached threads are not joinable with \ref osThreadJoin. When a detached thread is terminated, all resources are returned to
524 the system. The behavior of \ref osThreadDetach on an already detached thread is undefined.
526 Possible \ref osStatus_t return values:
527 - \em osOK: the attribute of the specified thread has been changed to detached successfully.
528 - \em osErrorParameter: \a thread_id is \token{NULL} or invalid.
529 - \em osErrorResource: thread specified by parameter \em thread_id is in an invalid thread state.
530 - \em osErrorISR: the function \b osThreadDetach cannot be called from interrupt service routines.
532 \note This function \b cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
535 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
537 \fn osStatus_t osThreadJoin (osThreadId_t thread_id)
539 The function \b osThreadJoin waits for the thread specified by \em thread_id to terminate. If that thread has already
540 terminated, then \ref osThreadJoin returns immediately. The thread must be joinable. By default threads are created with the
541 attribute \ref osThreadDetached.
543 Possible \ref osStatus_t return values:
544 - \em osOK: if the thread has already been terminated and joined or once the thread has been terminated and the join
546 - \em osErrorParameter: \a thread_id is \token{NULL} or invalid.
547 - \em osErrorResource: parameter \em thread_id is \token{NULL} or refers to a thread that is not an active thread or the
548 thread is not joinable.
549 - \em osErrorISR: the function \b osThreadJoin cannot be called from interrupt service routines.
551 \note This function \b cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
554 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
556 \fn __NO_RETURN void osThreadExit (void)
559 The function \b osThreadExit terminates the calling thread. This allows the thread to be synchronized with \ref osThreadJoin.
561 \note This function \b cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
565 __NO_RETURN void worker (void *argument) {
573 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
575 \fn osStatus_t osThreadTerminate (osThreadId_t thread_id)
577 The function \b osThreadTerminate removes the thread specified by parameter \a thread_id from the list of active threads. If
578 the thread is currently \ref ThreadStates "RUNNING", the thread terminates and the execution continues with the next \ref ThreadStates "READY" thread. If no
579 such thread exists, the function will not terminate the running thread, but return \em osErrorResource.
581 Possible \ref osStatus_t return values:
582 - \em osOK: the specified thread has been removed from the active thread list successfully.
583 - \em osErrorParameter: \a thread_id is \token{NULL} or invalid.
584 - \em osErrorResource: thread specified by parameter \em thread_id is in an invalid thread state or no
585 other \ref ThreadStates "READY" thread exists.
586 - \em osErrorISR: the function \b osThreadTerminate cannot be called from interrupt service routines.
588 \note This function \b cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
589 \note Avoid calling the function with a \em thread_id that does not exist or has been terminated already.
593 #include "cmsis_os2.h"
595 void Thread_1 (void *arg); // function prototype for Thread_1
597 void ThreadTerminate_example (void) {
601 id = osThreadNew (Thread_1, NULL, NULL); // create the thread
603 status = osThreadTerminate (id); // stop the thread
604 if (status == osOK) {
605 // Thread was terminated successfully
608 // Failed to terminate a thread
614 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
616 \fn uint32_t osThreadGetStackSize (osThreadId_t thread_id)
618 The function \b osThreadGetStackSize returns the stack size of the thread specified by parameter \a thread_id. In case of an
619 error, it returns \token{0}.
621 \note This function \b cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
624 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
626 \fn uint32_t osThreadGetStackSpace (osThreadId_t thread_id);
628 The function \b osThreadGetStackSpace returns the size of unused stack space for the thread specified by parameter
629 \a thread_id. Stack watermark recording during execution needs to be enabled (refer to \ref threadConfig). In case of an
630 error, it returns \token{0}.
632 \note This function \b cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
635 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
637 \fn uint32_t osThreadGetCount (void)
639 The function \b osThreadGetCount returns the number of active threads or \token{0} in case of an error.
641 \note This function \b cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
644 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
646 \fn uint32_t osThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items)
648 The function \b osThreadEnumerate returns the number of enumerated threads or \token{0} in case of an error.
650 \note This function \b cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
656 // these struct members must stay outside the group to avoid double entries in documentation
658 \var osThreadAttr_t::attr_bits
660 The following predefined bit masks can be assigned to set options for a thread object.
662 | Bit Mask | Description |
663 | :---------------------- | :------------------------------------------------------ |
664 | \ref osThreadDetached | Create thread in a detached mode (default). |
665 | \ref osThreadJoinable | Create thread in joinable mode, see \ref osThreadJoin. |
668 \var osThreadAttr_t::cb_mem
670 Pointer to a memory location for the thread control block object. This can optionally be used for custom memory management systems.\n
671 Default: \token{NULL} (uses kernel memory management).
673 \var osThreadAttr_t::cb_size
675 The size of the memory block passed with \ref cb_mem. Must be the size of a thread control block object or larger.
677 \var osThreadAttr_t::name
679 Pointer to a string with a human readable name of the thread object.\n
680 Default: \token{NULL}.
682 \var osThreadAttr_t::priority
684 Specifies the initial thread priority with a value from #osPriority_t.\n
685 Default: \token{osPriorityNormal}
687 \var osThreadAttr_t::reserved
689 Reserved for future use (set to '0').\n
692 \var osThreadAttr_t::stack_mem
694 Pointer to a memory location for the thread stack, \b must be 64-bit aligned. This can optionally be used for custom memory
695 management systems.\n
696 Default: \token{NULL} (uses kernel memory management).
698 \var osThreadAttr_t::tz_module
700 TrustZone Thread Context Management Identifier to allocate context memory for threads. The RTOS kernel that runs in
701 non-secure state calls the interface functions defined by the header file TZ_context.h.
702 See <a href="../../Core/html/group__context__trustzone__functions.html">TrustZone RTOS Context Management</a>.
704 \var osThreadAttr_t::stack_size
706 The size of the stack specified by \ref stack_mem in Bytes.