Questions: Producer-Consumer Problem: Classic Synchronization

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A producer acquires the mutex first, then waits on the empty-slot semaphore. The buffer is currently full. What happens?

ADeadlock: the producer holds the mutex while blocked on the semaphore, preventing any consumer from acquiring the mutex to free a slot
BThe producer waits on the semaphore and automatically releases the mutex while blocked
CA consumer signals the empty-slot semaphore from outside the critical section, unblocking the producer
DThe OS detects the contention and suspends the producer temporarily without causing deadlock
Question 2 Multiple Choice

In a condition-variable-based producer-consumer implementation, why must the wait() call always appear inside a while loop rather than an if statement?

AA while loop retries the operation automatically on failure, which is required for liveness
BSpurious wakeups and the possibility that another thread consumed the resource before this thread runs require rechecking the condition after every wakeup
CThe monitor semantics require that wait() be called at least twice before a thread proceeds
DIf statements cannot appear inside synchronized code due to OS scheduling constraints
Question 3 True / False

In the semaphore-based producer-consumer solution, the mutex is acquired after the counting semaphore (not before) to prevent the producer from blocking while holding the mutex.

TTrue
FFalse
Question 4 True / False

A producer and consumer operating on a bounded buffer seldom need synchronization as long as they access different cells in the buffer at the same time.

TTrue
FFalse
Question 5 Short Answer

Describe the deadlock that occurs when a producer acquires the mutex before waiting on the counting semaphore, and explain the rule that prevents it.

Think about your answer, then reveal below.