🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← All topics

Quiz: Semaphores and Classic Problems: questions with answers

9 questions, each with the answer and a short explanation.

Take the timed quiz + get a certificate →
  1. Q1. In the textbook implementation, a semaphore's value is −3. What does that mean?
  2. Q2. A semaphore starts at x. After 8 waits and 3 signals its value is 1. What is x?
  3. Q3. Two threads each run x = x + 1 once on shared x = 0, with no lock. Which final values are possible?
  4. Q4. In the bounded buffer, which semaphore makes the producer block when the buffer is full?
  5. Q5. Why must signal() check "value ≤ 0" rather than "value < 0" before waking a process?
  6. Q6. In the readers-first readers-writers solution, which reader performs wait(rw)?
  7. Q7. Which change makes the dining philosophers deadlock-free?
  8. Q8. What does this print? (code)
  9. Q9. What is the main problem with a busy-waiting (spinlock) wait()?