CS FundamentalsVery hardGATE CS
A barrier for N threads is implemented with count (protected by mutex) and a semaphore barrier = 0: each thread does `lock; count++; if (count == N) signal(barrier); unlock; wait(barrier); signal(barrier);`. What is the purpose of the final signal(barrier)?
- A. It forms a turnstile: each thread that passes lets the next one through, so all N threads get past the barrier
- B. It resets count to 0 for reuse
- C. It prevents deadlock between mutex and barrier
- D. It is unnecessary; removing it changes nothing
Correct answer: A. It forms a turnstile: each thread that passes lets the next one through, so all N threads get past the barrier
Only the last arriving thread signals once; without the extra signal only one waiter would pass. The pass-it-on signal releases all N (leaving barrier = 1 afterwards, which is why this simple version is not reusable).
More Operating Systems questions
- Processes (arrival, burst): P1 (0, 12), P2 (2, 4), P3 (3, 6), P4 (8, 5), P5 (10, 2). Under SRTF, which process waits the longest, and for…
- Processes (arrival, burst): A (0, 5), B (1, 7), C (3, 2), D (4, 6). Round Robin with quantum 4 (new arrivals queued before a preempted…
- Processes (arrival, burst, priority; smaller number = higher priority): P1 (0, 3, 2), P2 (1, 6, 1), P3 (2, 4, 3), P4 (12, 2, 1), P5 (13…
- Processes (arrival, burst): A (0, 6), B (2, 6), C (5, 9), D (5, 8), E (5, 2). Under non-preemptive HRRN, what is the average waiting time?
- Two processes each alternate CPU and I/O: P1 = CPU 4, I/O 6, CPU 2; P2 = CPU 3, I/O 3, CPU 5 (ms). Both arrive at 0, P1 first; scheduling…
- Reference string: 7, 2, 3, 1, 2, 5, 3, 4, 6, 7, 7, 1, 0, 5, 4, 6, 2, 3, 0, 1. With 3 frames (initially empty), what are the page-fault…