GATE CSE 2018 Q50: Placing empty/full semaphores in a producer-consumer solution
- Operating System
- 2 marks
- MCQ
- −2/3 if wrong
Syllabus topic: Inter-process communication, concurrency and synchronization
Question
Consider the following solution to the producer-consumer synchronization problem. The shared buffer size is . Three semaphores empty, full and mutex are defined with respective initial values of 0, 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:
do{
wait(P);
wait(mutex);
//Add item to buffer
signal(mutex);
signal(Q);
}while(1);
Consumer:
do{
wait(R);
wait(mutex);
//Consume item from buffer
signal(mutex);
signal(S);
}while(1);Which one of the following assignments to P, Q, R and S will yield the correct solution?
Try it: multiple choice: exactly one correct option
Show answer and explanation
Answer: C (official GATE 2018 final answer key)
Concept used: In the bounded-buffer solution, each side waits on the semaphore counting what it needs (free slots for the producer, filled slots for the consumer) and signals the semaphore the other side waits on.
First step: Note the unusual naming here: full (initially ) counts free slots, so the producer must wait on it; then decide what the producer should signal for the consumer.
Full step-by-step solution
Loading…
Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.
More questions on Inter-process communication, concurrency and synchronization
Every PYQ on this topic →Share this question
Source: official GATE 2018 CS question paper and final answer key, organised by IIT Guwahati. Question paper · Answer key
More Operating System PYQs
- 2026 Session 1 · Q29False statements about deadlocks
- 2026 Session 1 · Q35Minimum resource instances for deadlock freedom (5 processes, max 2)
- 2026 Session 1 · Q59Disk transfer time for random sectors on tracks 5, 12, 7
- 2026 Session 1 · Q63Number of printf calls with fork, continue and break
- 2026 Session 1 · Q64Average FCFS waiting time for alternating A and C processes
- 2026 Session 2 · Q23CPU scheduling algorithm that cannot be preemptive