|
Using Multi-Threading in Contiki
|
|
|
Written by Adam Dunkels,
Tuesday, 23 January 2007 |
|
Unlike other embedded operating systems, Contiki supports both an event-driven execution model and multi-threading. (And protothreads, of course.) Using multi-threading in Contiki is easy, but it requires you to be explicit about it: read on for the details.
The principle behind the Contiki multi-threading library is simple: create a thread with the mt_start() function and call mt_exec() to schedule the thread. After a call to mt_exec() the thread will run until the thread calls mt_yield() or mt_exit(). The thread is represented by a variable of type struct mt_thread. This structure contains the full state of the thread, including the thread’s stack.
Scheduling the thread typically is done in a Contiki process. By repeatedly posting continuation events to itself, the process can schedule the thread so that it runs continuously.
See the Contiki documentation for more information: http://www.sics.se/~adam/contiki/docs/ |