Question:

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?

Show Hint

In thread context switching, save only the thread-specific CPU state (SP, PC, registers).
In process context switching, save both CPU state and memory-related state (page tables, segment tables).
Updated On: Aug 26, 2025
  • Page table base register
  • Stack pointer
  • Program counter
  • General purpose registers
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

Step 1: Understanding context switch
When switching from one thread (T1) to another (T2) within the same process, the CPU must save the current execution state of T1 and load the execution state of T2.
This execution state primarily consists of CPU registers and pointers required to resume execution later.
Step 2: Evaluating each option
- (A) Page table base register:
All threads of the same process share the same virtual address space, hence the same page table base register.
Therefore, it does not need to be saved or changed during a thread-to-thread context switch.
\(\Rightarrow\) Not required.
- (B) Stack pointer:
Each thread maintains its own stack (for function calls, local variables, return addresses).
To resume T2 correctly, its stack pointer must be restored.
\(\Rightarrow\) Must be saved/restored.
- (C) Program counter:
The program counter (PC) holds the address of the next instruction to execute.
Without saving/restoring the PC, the thread cannot resume from where it left off.
\(\Rightarrow\) Must be saved/restored.
- (D) General purpose registers:
General purpose registers (like AX, BX in x86, or r0, r1 in ARM) hold intermediate data during computation.
Each thread requires its own register values to resume correctly.
\(\Rightarrow\) Must be saved/restored.
Step 3: Conclusion
Only the thread-specific state (stack pointer, program counter, and general registers) needs to be saved/restored.
The address-space-related state (page table base register) remains unchanged because threads of a process share memory.
\[ \boxed{\text{Correct Statements: (B), (C), and (D)}} \]
Was this answer helpful?
0
0

Questions Asked in GATE CS exam

View More Questions