Oasis One-Key Well
Two caravans reached the last water jug at once! Build a one-key well keeper so shared supplies can never be changed by two workers together.
π§ Before we start
In the movie studio, your undo stack allowed one newest edit at a time. Today, a mutex is a one-owner key. It guards a critical sectionβthe short, shared job that only one worker may do safely.
Arrange the well protocol
Tap five visual instruction cards in the safe order. The key must surround the shared water update.
Expose the race condition
There is one jug left and no key. Follow the step-by-step schedule. Both caravans can read the same old supply before either saves a change.
Guard the critical section
Welcome all three caravans. Only the key owner may draw and save. Finish each turn to return the key to the next caravan.
FREE
EMPTY
Debug the missing release
A bucket rope breaks while Caravan A owns the key. The broken path forgets to return it, so every waiting caravan is stuck. Choose the robust repair.
key never returns
π What you learned
- A race condition appears when timing lets workers change the same data from stale information.
- A mutex acts like a one-owner key for shared data.
- The critical section is the protected read-change-save job.
- Other workers wait in a queue while the key is owned.
- The owner must release the key on success and on every error path.