Which one or more of the following need to be saved on a context switch from…
2023
Which one or more of the following need to be saved on a context switch from one thread (T1) of a process to another thread (T2) of the same process?
- A.
Page table base register
- B.
Stack pointer
- C.
Program counter
- D.
General purpose registers
Attempted by 170 students.
Show answer & explanation
Correct answer: B, C, D
Key result: on a context switch between threads of the same process you must save and restore per-thread CPU state (stack pointer, program counter, general-purpose registers).
Stack pointer — each thread has its own stack, so save the stack pointer to resume that thread's stack frame.
Program counter — save the instruction pointer so the thread can continue from the correct instruction when scheduled again.
General purpose registers — save registers holding temporary values and CPU state; they are part of the thread context.
Not required to save:
Page table base register — threads within the same process share the same address space and page table, so the page table base does not change on a thread-to-thread switch.