CS FundamentalsHardProduct-company MCQ pattern
Producer–consumer with semaphores mutex = 1, empty = N, full = 0. The producer is written as:
Producer–consumer with semaphores mutex = 1, empty = N, full = 0. The producer is written as:
wait(mutex); wait(empty); /* add item */ signal(mutex); signal(full);The consumer is correct (wait(full); wait(mutex); … signal(mutex); signal(empty);). What can go wrong?
- A. Nothing; the order of the two waits does not matter
- B. Deadlock when the buffer is full: the producer holds mutex while blocked on empty, so the consumer can never enter
- C. Two producers can add items at the same time
- D. The consumer can remove from an empty buffer
Correct answer: B. Deadlock when the buffer is full: the producer holds mutex while blocked on empty, so the consumer can never enter
If the buffer is full, the producer acquires mutex and then blocks on empty. The consumer passes wait(full) but blocks on wait(mutex), so neither can proceed. The counting semaphore must be waited on before the mutex.
More Operating Systems questions
- Match each scheduling algorithm with its property: (P) Round Robin (Q) SRTF (R) Multilevel feedback queue (S) FCFS (1) Moves processes…
- How many of the following statements are correct? 1. On a context switch, the TLB must be flushed unless its entries carry an…
- A 16 GB disk is formatted with 4 KB blocks and a File Allocation Table (FAT) that has one 4-byte entry per block. How large is the FAT…
- How many of the following statements about semaphores and mutexes are correct? 1. A binary semaphore can be used to achieve mutual…
- Process L (low priority) holds a lock that high-priority process H needs. Medium-priority process M, which does not need the lock, becomes…
- Consider this loop: c for (int i = 0; i < 2; i++) { fork(); printf("-"); } stdout is redirected to a file (fully buffered) and no fflush…