Contiki does not support preemptive multitasking in a true sense. Actually, it is a event based OS and events are fired to the concerned processes in a FIFO manner. The event handlers run to completion i.e., once scheduled they are not preemptive by the OS. In Contiki, multithreading is implemented on top of event driven kernel, as events run to completion, therefore OS does not preemptive a thread once scheduled. To give an illusion of preemptive multitasking threads must explicitly yield or wait for some event and you need to write a scheduler to schedule your threads.
Best regards,
|
-----Inline Attachment Follows----- |
Hi,
Regards,
Michal Ulianko
------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
Trying to clarify the obviously not so obvious ;-)
1. Contiki itself is built and uses protothreads. As they share a
single stack they for sure are non-preemptive.
2. Totally unrelated to the rest of Contiki there's the
multi-threading library. Note that the name says nothing about
preemtion! That library defines an interface for threads with
individual stacks (in contrast to the shared stack protothreads).
Those threads can either be scheduled in an non-preemptive fashion
(relying on the threads calling mt_yield() _OR_ in a preemptive way.
The docs referenced below say:
"Additionally, two functions for controlling the preemption (if any)
must be implemented: mtarch_pstart() and mtarch_pstop(). If no
preemption is used, these functions can be implemented as empty
functions."
So with the background above it should be clear that the two functions
are supposed to start / stop the preemptive scheduler. Usually that
would be some timer interrupt handler doing thread context switching.
According to my knowledge there's no "architecture support for
multi-threading" implementation that supports preemption. Therefore
the multi-threading example program I wrote presumes non-preemption:
http://contiki.git.sourceforge.net/git/gitweb.cgi?p=contiki/contiki;a=blob_plain;f=examples/multi-threading/multi-threading.c;hb=HEAD
One might ask what the usecases of non-preemptive scheduled threads
with individual stacks are. The example program shows one: Recursion.
Regards,
Oliver
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure
> contains a definitive record of customers, application performance,
> security threats, fraudulent activity, and more. Splunk takes this
> data and makes sense of it. IT sense. And common sense.
> http://p.sf.net/sfu/splunk-novd2d
> _______________________________________________
> Contiki-developers mailing list
> Contiki-d...@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/contiki-developers
>
>
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d