DSA Factory
Free Synchronization lessonsSynchronization · Stage 1 · Locks and semaphores · Step 2

Semaphores

Understand the counter-with-a-queue that can guard a resource pool and also order events between threads. About 13 minutes.

Quick check

A semaphore starts at 0. Thread B calls wait and thread A later calls signal. What is this pattern for?

  1. AMaking B wait until A has done something: ordering events
  2. BMutual exclusion around a critical section
  3. CLimiting access to a pool of identical resources
Show the answer

Making B wait until A has done something: ordering events. B blocks until A signals, so B can't run ahead of A.

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