GATE CS 2018 (Forenoon) — Question 50

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

Consider the following solution to the producer-consumer synchronization problem. The shared buffer size is \(N\). Three semaphores empty, full and mutex are defined with respective initial values of 0, \(N\) and 1. Semaphore empty denotes the number of available slots in the buffer, for the consumer to read from. Semaphore full denotes the number of available slots in the buffer, for the producer to write to. The placeholder variables, denoted by P, Q, R, and S, in the code below can be assigned either empty or full. The valid semaphore operations are: wait() and signal(). Producer:
c
1do{
2    wait(P);
3    wait(mutex);
4    //Add item to buffer
5    signal(mutex);
6    signal(Q);
7}while(1);
8
Consumer:
c
1do{
2    wait(R);
3    wait(mutex);
4    //Consume item from buffer
5    signal(mutex);
6    signal(S);
7}while(1);
8
Which one of the following assignments to P, Q, R and S will yield the correct solution?
  1. A
    P: full, Q: full, R: empty, S: empty
  2. B
    P: empty, Q: empty, R: full, S: full
  3. C
    P: full, Q: empty, R: empty, S: full
  4. D
    P: empty, Q: full, R: full, S: empty
Practise the full 2018-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