DSA Factory
Free Synchronization lessonsSynchronization · Stage 2 · The classic problems · Step 1

Producer and consumer

Solve the bounded-buffer problem with semaphores, and see how one wrong ordering causes deadlock. About 14 minutes.

Quick check

In the bounded-buffer solution, what does the full semaphore count?

  1. AThe number of items currently in the buffer
  2. BThe number of free slots
  3. CThe number of waiting threads
Show the answer

The number of items currently in the buffer. Consumers wait on it; producers signal it after adding an item.

Lock it in

4 questions on this idea

Short questions that apply the idea to new cases: trace it, work out a number, put steps in order. A wrong answer explains itself.

Answer them in your browserFree account, no card. Your progress is saved, and the idea comes back in a quick review later.
Sign up free to solve