Studio Lock Ordering
The studio owns just one camera, one microphone and one light. Every film crew needs two of them at once. Make sure no crew ever freezes the whole set.
π§ Before we start
Treehouse LRU Shelf shared a small shelf between requests. Today several crews share a few locked tools: only one crew can hold a tool at a time. If crews each hold a tool the other needs, they wait on each other forever. That freeze is called a deadlock.
Build the crew routine
Every crew follows the same plan for the two tools it needs. Tap the four cards in the order a careful crew does them.
Frozen or just waiting?
Waiting is normal. Deadlock only happens when the waiting forms a circle that can never open. Follow each crew's "wants" chain and judge the set.
Rank the tools
Break the circle with one rule: every tool gets a rank and every crew locks tools from the lowest rank to the highest. Flip any crew that asks in the wrong order, then roll the cameras on the worst start.
Why one order wins
Three crews film three different takes with different start orders. Replay all three takes under each rule, compare how many finish, then lock in the safer rule.
π What you learned
- A lock lets only one worker use a shared resource at a time. Others must wait.
- Waiting alone is fine. A deadlock is a circle of workers who each hold something the next one needs.
- Holding one lock while asking for another is how that circle forms.
- Giving every lock a rank and always asking in rank order makes a circle impossible.
- Deadlocks can hide: they only show up with unlucky timing, so a rule that prevents them beats hoping for luck.