CS FundamentalsHardGATE CS

A counting semaphore is implemented WITHOUT busy waiting: wait() decrements the value and, if it becomes negative, puts the caller on the semaphore's queue and blocks it. What must be true of wait() and signal() themselves?

  1. A. They must be called only from user mode
  2. B. They must execute atomically, e.g. by a short spinlock or by disabling interrupts on a uniprocessor
  3. C. They need no protection because the queue handles races
  4. D. They must always context switch

Correct answer: B. They must execute atomically, e.g. by a short spinlock or by disabling interrupts on a uniprocessor

The test-and-decrement and queue manipulation are themselves critical sections; a brief spinlock (multiprocessor) or interrupt disabling (uniprocessor) protects them. The busy waiting is thus moved to these very short sections.

More Operating Systems questions

Exams that ask this topic