5
$\begingroup$

Many small embedded systems have a limited amount of RAM, 10k or less. I know you can run an RTOS on such systems, however, a realistic number of tasks in such a system is very low, mainly because every task needs its own stack area.

Is it possible to share the space needed for the stack of some of these tasks?

I understand that this is possible in a cooperative environment, such that a task can report its willingness to relinquish the processor (and refrain from using its stack). But in an RTOS you don't normally use cooperative multitasking.
But then, maybe it is sufficient to use non-preemptive tasks when sharing stack space, in a certain way that's also "cooperative" in my opinion.

Can it be done in an RTOS? How?

$\endgroup$
4
$\begingroup$

As long as they do not overlap in execution, the tasks can re-use the same stack space. That is, they can not safely execute in parallel or else one task will corrupt another's stack space.

This corruption may occur due to local variables or parameters stored on the stack, or even due to the occurrence of an ISR.

Hope this helps

$\endgroup$
  • 1
    $\begingroup$ Agreed. But can you use such a technique in a real-time OS? And which technique to use? Cooperative multi-tasking is a solution, but not really fit for an RTOS, unless I'm mistaken. The comment from @atur indicates an interesting solution. So, yes, it can be done. Are there others? $\endgroup$ – Johan Bezem Aug 26 '14 at 14:53
  • 1
    $\begingroup$ As long as certain restrictions are met, I don't see why it could not work in an RTOS. A preemptive solution that allows non-cooperative switches between tasks in the same stack sharing set would not be feasible, but one that allows non-cooperative switches between tasks not in the same stack sharing set would be feasible. $\endgroup$ – Sparky Aug 26 '14 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.