Embedded / RTOS

Moderators: None (Apply to moderate this forum)
Number of threads: 373
Number of posts: 682

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
RTEMS or general RTOS question Posted by bogdanul2003 on 12 Feb 2012 at 11:08 AM
Hello,

I am developing an application for RTEMS that involves two running tasks. Both tasks call at some point the same global function called function1.
Let's say task T1 calls function1 and the context switch to T2 occurs before exiting function1. Task T2 also calls function1.
My question is what happens to the local variables of function1? ... is there a copy of function1 for each task ?

Thanks
Report
Re: RTEMS or general RTOS question Posted by KenJackson on 14 Feb 2012 at 6:38 PM
I don't know anything specifically about RTEMS, but I would be shocked if they don't have separate stacks for each thread.

Each thread pushes parameters on its own stack and calls the function. Then the function adjusts the stack pointer to take as much space as it needs for its local variables.

A task switch stores all registers, including the stack pointer, in the task structure for the task that's being suspended and loads them from the structure for the task being activated.

There's only one copy of the code, but multiple stacks.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.