GATE CS 2024 (Afternoon) — Question 46

Operating Systems (OS)Concurrency & Synchronization (Semaphores, Mutex, Monitors, Locks)MSQ2 marksMedium

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.
c
1// code of T1
2wait (s1);
3x = x + 1;
4print(x);
5wait(s2);
6signal(s1);
7
8// code of T2
9wait (s1);
10x = x + 1;
11print(x);
12signal(s2);
13signal(s1);
14
Which of the following outcomes is/are possible when threads T1 and T2 execute concurrently?
  1. A
    T1 runs first and prints 1, T2 runs next and prints 2
  2. B
    T2 runs first and prints 1, T1 runs next and prints 2
  3. C
    T1 runs first and prints 1, T2 does not print anything (deadlock)
  4. D
    T2 runs first and prints 1, T1 does not print anything (deadlock)
Practise the full 2024-AN paper
Challenge a friend: WhatsApp Telegram
Recommended book · affiliate linkOperating System Concepts (Galvin)Scheduling, synchronisation, deadlocks, memory and file systems.
Practise more on Concurrency & Synchronization (Semaphores, Mutex, Monitors, Locks)Timed, in the real exam interface · free to start

A GATE question every morning

One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.

Join
Stuck? Ask in the student group