How does context switching work?

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Nov 2 06:18:56 UTC 2020


On 31/10/2020 16:50, Richi Dubey wrote:

>
> I want to learn more about how context switching works in RTEMS. I saw 
> the following lines in theaddispatch.c:
>
>     _Thread_Save_fp( executing );
>     _Context_Switch( &executing->Registers, &heir->Registers );
>     _Thread_Restore_fp( executing );
>
> I do not understand how it works. Here, the executing process saves 
> its context by calling _Thread_Save_fp( executing ), then if a 
> different process resumes execution after the context switch, why does 
> it get the context of previous process (executing)?
The _Context_Switch() function changes the thread stack and the 
non-volatile (callee save) registers. So, the value of the executing 
local variable changes with a call to _Context_Switch().

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber at embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.



More information about the devel mailing list