RTEMS or general RTOS question - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

RTEMS or general RTOS question


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 ?



  • KenJacksonKenJackson Posts: 7Member
    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.
Sign In or Register to comment.