CS FundamentalsHardGATE CS · Amazon/Microsoft SDE MCQ
A bounded buffer uses semaphores empty = N, full = 0 and mutex = 1. The producer is changed to do wait(mutex) BEFORE wait(empty); the consumer still does wait(full) then wait(mutex). What can happen?
- A. Two producers can enter the buffer together, so an item in a slot gets overwritten
- B. A consumer can remove an item from an empty buffer and so read a stale slot value
- C. With a full buffer the producer sleeps on empty holding mutex, and the consumer blocks on mutex: deadlock
- D. Nothing changes in behaviour, since every wait() is still matched by a signal()
Correct answer: C. With a full buffer the producer sleeps on empty holding mutex, and the consumer blocks on mutex: deadlock
With a full buffer the producer takes mutex and sleeps on empty, still holding mutex. The consumer passes wait(full) but then waits for mutex forever, so nobody can signal empty. Counting semaphores must be acquired before the mutex.
More Operating Systems questions
- Jobs A (6), B (2), C (8) and D (3) all arrive at time 0 in that order. What are the average waiting time under non-preemptive SJF and the…
- Under Linux CFS, two CPU-bound tasks share one CPU: one at nice 0 (weight 1024) and one at nice 5 (weight 335). About what share of CPU…
- A system's average process size is s = 1 MB and each page-table entry takes e = 8 bytes. Balancing page-table overhead (s·e / p) against…
- What does this program print? (Assume fork() succeeds and the exec of echo succeeds.) c int main() { fork(); execlp("echo", "echo", "hi"…
- In a traditional Unix file system (such as ext2/ext4 without very large directories), directory /d contains 3 subdirectories and 5 regular…
- A process with umask 027 creates a regular file requesting mode 0666 and a directory requesting mode 0777. What permissions do they get?