GATE / CS ARCHIVE

GATE CSE 2018 / QUESTION 40

Semaphore roles despite reversed names

Operating Systems · Synchronization & Concurrency · Full GATE CSE 2018 paper

GATE 2018, Q40 2 marks · MCQ
Report issue

Synchronization & Concurrency

Question 40, GATE 2018: A size-N buffer uses empty=0, full=N, mutex=1. Here empty counts readable items and full writable slots. Producer executes wait(P),wait(mutex),add,signal(mutex),signal(Q); consumer wait(R),wait(mutex),remove,signal(mutex),signal(S). Choose A full/full/empty/empty; B empty/empty/full/full; C full/empty/empty/full; D empty/full/full/empty.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Method

Follow the definitions rather than familiar variable names. Before adding an item, the producer must reserve one writable slot, so it waits on the semaphore initially N. After insertion it creates a readable item, so it signals the semaphore initially 0. The consumer performs the reverse transfer. Waiting for a resource before taking mutex also avoids holding the buffer lock while blocked for another process to make progress. Each successful pair of operations preserves the bounded-buffer accounting.

Solution

Use the definitions supplied, which reverse the usual semaphore names. full starts N and counts producer-writeable slots; empty starts 0 and counts readable items. The producer waits(full) and signals(empty); the consumer waits(empty) and signals(full), each using mutex for buffer access. Thus P=full, Q=empty, R=empty, S=full, C.

Original paper, page 17 · Answer key