CS FundamentalsHardGATE CS
Binary semaphore mutex = 1 protects a counter. A programmer mistakenly writes `signal(mutex); /* critical section */ wait(mutex);` in every process. What happens?
- A. Several processes can be in the critical section at once
- B. The first process to run deadlocks
- C. Only one process ever enters, then all others starve
- D. It still works correctly, only slower
Correct answer: A. Several processes can be in the critical section at once
signal first raises mutex to 2 (a counting implementation) or leaves it 1, so each process walks straight in; mutual exclusion is lost. Swapping two waits instead (wait; wait) would cause deadlock.
More Operating Systems questions
- In the dining philosophers problem with 5 philosophers, each picks up the LEFT fork and then the RIGHT fork. Which change by itself…
- Readers–writers with readers' preference: semaphores mutex = 1 (protects readcount), wrt = 1. Reader: wait(mutex); readcount++; if…
- A bounded buffer of size N uses semaphores empty = N, full = 0, mutex = 1. Producer: wait(empty); wait(mutex); add; signal(mutex)…
- 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")…