Support for multi-threading. More...
As RIOT is using a fixed priority scheduling algorithm, threads are scheduled based on their priority. The priority is fixed for every thread and specified during the thread's creation by the
The lower the priority value, the higher the priority of the thread, with 0 being the highest possible priority.
The lowest possible priority is THREAD_PRIORITY_IDLE - 1.
In addition to the priority, flags can be used when creating a thread to alter the thread's behavior after creation. The following flags are available:
|THREAD_CREATE_SLEEPING||the thread will sleep until woken up manually|
|THREAD_CREATE_WOUT_YIELD||the thread might not run immediately after creation|
|THREAD_CREATE_STACKTEST||measures the stack's memory usage|
Creating a new thread is internally done in two steps:
Reading from the top down, you can see that first, stack memory for our thread
rcv_thread is preallocated, followed by an implementation of the thread's function. Communication between threads is done using Messaging / IPC. In this case,
rcv_thread will print the process id of each thread that sent a message to
After it has been properly defined,
rcv_thread is created with a call to thread_create() in
main(). It is assigned a priority of
THREAD_PRIORITY_MAIN - 1, i.e. a slightly higher priority than the main thread. Since neither the
THREAD_CREATE_SLEEPING nor the
THREAD_CREATE_WOUT_YIELD flag is set,
rcv_thread will be executed immediately.
|Threading API. |
|Thread flags. |
|Describes an illegal thread status. |
|has terminated |
|waiting for a locked mutex |
|waiting for a message |
|waiting for message to be delivered |
|waiting for a message response |
|waiting for any flag from flag_mask |
|waiting for all flags in flag_mask |
|waiting for get/put on mbox |
|to check if on run queue: |
|currently running |
|waiting to be scheduled to run |