Exams › GATE › Technical
Consider a multi-threaded program with two threads T1 and T2. The threads share two semaphores: s1 (initialized to 1) and s2 (initialized to 0). The threads also share a global variable x (initialized to 0). The threads execute the code shown below.
// code of T1
wait(s1);
x = x+1;
print(x);
wait(s2);
signal(s1);
// code of T2
wait(s1);
x = x+1;
print(x);
signal(s2);
signal(s1);
Which of the following outcomes is/are possible when threads T1 and T2 execute concurrently?
- T1 runs first and prints 1, T2 runs next and prints 2
- T2 runs first and prints 1, T1 runs next and prints 2
- T1 runs first and prints 1, T2 does not print anything (deadlock)
- T2 runs first and prints 1, T1 does not print anything (deadlock)
Correct answer: T1 runs first and prints 1, T2 does not print anything (deadlock)
Solution
The correct option describes a scenario where T1 successfully increments and prints the value of x before waiting on s2, which is not signaled by T2. Since T2 cannot proceed without the signal from T1, it leads to a deadlock situation where T2 is blocked and cannot print anything.
Related GATE Technical questions
- Once the DBMS informs the user that a transaction has been successfully completed, its effect should persist even if the system crashes before all its changes are reflected on disk. This property is called
- In the context of owner and weak entity sets in the E R (Entity-Relationship) data model, which one of the following statements is TRUE?
- Node X has a TCP connection open to node Y. The packets from X to Y go through an intermediate IP router R. Ethernet switch S is the first switch on the network path between X and R. Consider a packet sent from X to Y over this connection. Which of the following statements is/are TRUE about the destination IP and MAC addresses on this packet at the time it leaves X?
- Let M be the 5-state NFA with ε-transitions shown in the diagram below. Which one of the following regular expressions represents the language accepted by M ?
- The three-dimensional state of stress at a point is given by σ = [[10, 0, 0],[0, 40, 0],[0, 0, 0]] MPa. The maximum shear stress at the point is
- A 2 m wide strip footing is founded at a depth of 1.5 m below the ground level in a homogeneous pure clay bed. The clay bed has unit cohesion of 40 kPa. Due to seasonal fluctuations of water table from peak summer to peak monsoon period, the net ultimate bearing capacity of the footing, as per Terzaghi’s theory, will
⚔️ Practice GATE Technical free + battle 1v1 →