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.
A semaphore starts at 0. Thread B calls wait and thread A later calls signal. What is this pattern for?
- AMaking B wait until A has done something: ordering events
- BMutual exclusion around a critical section
- 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.
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