CS FundamentalsHardGATE CS
A bounded buffer of size N uses semaphores empty = N, full = 0, mutex = 1. Producer: wait(empty); wait(mutex); add; signal(mutex); signal(full). If the CONSUMER is written as wait(mutex); wait(full); remove; signal(mutex); signal(empty), when can the system deadlock?
- A. When the buffer is empty and the consumer gets mutex before a producer
- B. When the buffer is full and the producer runs first
- C. Never; the order of waits does not matter
- D. Only when N = 1
Correct answer: A. When the buffer is empty and the consumer gets mutex before a producer
With an empty buffer the consumer holds mutex and blocks on full; the producer then blocks on mutex and can never signal full. Waits on counting semaphores must come before the wait on mutex.
More Operating Systems questions
- Monitors versus semaphores: in a Hoare-style monitor, when a process executes x.signal() and some process is waiting on condition x, which…
- Why must a Mesa-style condition wait be written as while (!cond) wait(c); rather than if (!cond) wait(c);?
- How many times is "x" printed? (Every fork() succeeds.) c int main() { if (fork() == 0) { fork(); fork(); } else { fork(); } printf("xn")…
- How many processes print "x" (including the original)? (Every fork() succeeds.) c int main() { for (int i = 0; i < 4; i++) if (fork() !=…
- How many times is "x" printed? (Every fork() succeeds.) c int main() { pidt a = fork(); pidt b = fork(); if (a > 0 && b > 0) fork()…
- How many times is "x" printed? (Every fork() succeeds.) c int main() { if ((fork() && fork()) || fork()) fork(); printf("xn"); }