GATE CS 2024 Set 1 — Question 40
MCQ+2 / -0.67MediumRace Conditions & Critical SectionProcess SynchronizationOperating System
Operating System → Process Synchronization → Race Conditions & Critical Section
Last updated
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.
Which one of the following options lists all the possible combinations of values of a and b after both T1 and T2 finish execution?
| T1 | T2 |
|---|---|
| a = a + 1; | b = 2 * b; |
| b = b + 1; | a = 2 * a; |
A.
(a = 4, b = 4); (a = 3, b = 3); (a = 4, b = 3)
B.
(a = 3, b = 4); (a = 4, b = 3); (a = 3, b = 3)
C.
(a = 4, b = 4); (a = 4, b = 3); (a = 3, b = 4)
D.
(a = 2, b = 2); (a = 2, b = 3); (a = 3, b = 4)
Correct answer
(A) (a = 4, b = 4); (a = 3, b = 3); (a = 4, b = 3)
Solution
Let the statements be:
T1:
Constraint: must execute before .T2:
Constraint: must execute before .Initially .Analysis of variable :
Operations on are and .
Operations on are and .
We must respect thread order ( and ).
Total permutations of 4 instructions is .
Combined with thread constraints and , we get cycle: . Impossible.Thus, the set of possible values is .
T1:
Constraint: must execute before .T2:
Constraint: must execute before .Initially .Analysis of variable :
Operations on are and .
- If order is : . ()
- If order is : . ()
Operations on are and .
- If order is : . ()
- If order is : . ()
We must respect thread order ( and ).
Total permutations of 4 instructions is .
1.: , . Result: .
2.: , . Result: .
3.: , . Result: .
4.: , . Result: .
5.: , . Result: .
6.: , . Result: .
Possible outcomes: .Note: The outcome requires (for ) and (for ).Combined with thread constraints and , we get cycle: . Impossible.Thus, the set of possible values is .
More questions on Process Synchronization
2024 Set 1 Q24Which of the following statements about threads is/are TRUE?2024 Set 2 Q24Which of the following tasks is/are the responsibility/responsibilities of the memory management…2024 Set 2 Q25Consider a process P running on a CPU. Which one or more of the following events will always…2024 Set 1 Q25Which of the following process state transitions is/are NOT possible?2024 Set 2 Q37Consider a single processor system with four processes A, B, C, and D, represented as given below,…
Practice GATE CS PYQs with adaptive difficulty
Timed practice, skill tracking, and AI explanations — free to start.
Start practicing free