GATE CS 2023 (Forenoon) — Question 38

Operating Systems (OS)Concurrency & Synchronization (Semaphores, Mutex, Monitors, Locks)MCQ2 marks · −2/3 if wrongHard

Consider the two functions incr and decr shown below:
c
1incr( ) {
2    wait(s);
3    X = X + 1;
4    signal(s);
5}
6decr( ) {
7    wait(s);
8    X = X - 1;
9    signal(s);
10}
11
There are 5 threads each invoking incr once, and 3 threads each invoking decr once, on the same shared variable X. The initial value of X is 10. Suppose there are two implementations of the semaphore s, as follows: I-1: s is a binary semaphore initialized to 1. I-2: s is a counting semaphore initialized to 2. Let V1, V2 be the values of X at the end of execution of all the threads with implementations I-1, I-2, respectively. Which one of the following choices corresponds to the minimum possible values of V1, V2, respectively?
  1. A
    15, 7
  2. B
    7, 7
  3. C
    12, 7
  4. D
    12, 8
Practise the full 2023-FN 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