GATE CSE 2024 Session 1 Q40: Possible final values of a and b for two interleaved threads
- Operating System
- 2 marks
- MCQ
- −2/3 if wrong
Question
Consider the following two threads T1 and T2 that update two shared variables a and b. Assume that initially a = b = 1. Though context switching between threads can happen at any time, each statement of T1 or T2 is executed atomically without interruption.
| T1 | T2 |
|---|---|
| a = a + 1; | b = 2 * b; |
| b = b + 1; | a = 2 * a; |
Which one of the following options lists all the possible combinations of values of a and b after both T1 and T2 finish execution?
Try it: multiple choice: exactly one correct option
Show answer and explanation
Answer: A (official GATE 2024 final answer key)
Concept used: Enumerate interleavings that respect each thread's own statement order.
First step: a ends as 4 if a + 1 runs before 2 * a, else 3; do the same for b, then check which pairs an interleaving allows.
Full step-by-step solution
Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.
Share this question
Source: official GATE 2024 Session 1 CS question paper and final answer key, organised by IISc Bangalore. Question paper · Answer key
More Operating System PYQs
- 2026 Session 1 · Q29False statements about deadlocks
- 2026 Session 1 · Q35Minimum resource instances for deadlock freedom (5 processes, max 2)
- 2026 Session 1 · Q59Disk transfer time for random sectors on tracks 5, 12, 7
- 2026 Session 1 · Q63Number of printf calls with fork, continue and break
- 2026 Session 1 · Q64Average FCFS waiting time for alternating A and C processes
- 2026 Session 2 · Q23CPU scheduling algorithm that cannot be preemptive