CS FundamentalsVery hardGATE CS
Monitors versus semaphores: in a Hoare-style monitor, when a process executes `x.signal()` and some process is waiting on condition x, which statement is correct?
- A. The signal is remembered like a semaphore V even if no one waits
- B. Both processes continue running inside the monitor together
- C. The signalled process runs immediately and the signaller waits; if no process waits on x, the signal has no effect
- D. The signaller continues and the signalled process is woken only after the monitor is empty, and the signal is remembered
Correct answer: C. The signalled process runs immediately and the signaller waits; if no process waits on x, the signal has no effect
Condition variables have no memory: a signal with no waiter is lost (unlike a semaphore V). Hoare semantics hand the monitor straight to the woken process (signal-and-wait); Mesa semantics let the signaller continue (signal-and-continue), so waiters re-check conditions in a while loop.
More Operating Systems questions
- 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"); }
- How many times is "x" printed? (Every fork() succeeds; output is not buffered.) c int main() { for (int i = 0; i < 3; i++) { fork(); if (i…