.. include:: OS Primitives: Threads ====================== .. topic:: Documentation * :doc:`../code/threads` * `Zephyr: `__ Threads Basics -------------- .. topic:: See also * :doc:`/trainings/material/soup/linux/sysprog/posix-threads/index` * Scheduled by the OS: timeslices * Zephyr: cooperative vs. preemptive threads * One stack per thread * Threads may *block* on OS primitives like a :doc:`mutex <../code/locking>` or :doc:`message queue <../code/communication>`. * Priorities: when a higher priority thread becomes *runnable*, the currently running thread is *suspended*, and a *context switch* is made to run the higher priority thread Main Thread ----------- * One thread is always there, implicitly created * |longrightarrow| Main thread * Zephyr: runs at highest priority * |longrightarrow| Careful .. literalinclude:: code/mainthread.cpp :caption: :download:`code/mainthread.cpp` :language: c++ jjj Handler Threads -------------------