Previous | Next --- Slide 5 of 43
Back to Lecture Thumbnails
Richard

In the step 2, will the registers be recovered to be what they were like right before this thread was switched off last time?

I mean, in the step 3, this slide gives an example: "If the instruction is: add r0, r1, r2; then the processor adds the contexts of r1 and r2 and stores the result in r0". Before doing this, shouldn't r1 and r2 be filled with the values they are supposed to be? If so, is it in the step2? And are the values from like kernel memory?

lol

@above Yes, since the OS sets the "register values in that context to the last state of the thread". Therefore the previous register values (including r0, r1, r2, etc.) are loaded from storage and set into the execution context. So when the thread runs, it starts off at the same "state" at which it left off. So to the user, the context switch essentially hidden.

Similarly, when an execution context is swapped out, all the relevant information is stored to preserve the state (i.e. registers, program counter, segment selector, etc).