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)?

  1. A. It forms a turnstile: each thread that passes lets the next one through, so all N threads get past the barrier
  2. B. It resets count to 0 for reuse
  3. C. It prevents deadlock between mutex and barrier
  4. 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

Exams that ask this topic