Episode 39
The Two Tools Nobody Could Use
Two repair carts have got jammed up. One has the spanner. The other has the clamp. Neither of them will let go. Can Duck and Robot unjam the two jobs?


















Episode transcript
Two jobs reach for tools
In the monitor: Duck does the job A with a coral cart and Robot does the job B with an aqua cart. For both simulated jobs we have to use the spanner S and the clamp T which are available in the beginning (on a rack).
Diagram values: S:SPANNER; T:CLAMP; EACH JOB NEEDS S+T
Duck: Two repairs to make. Let's use two tools.
Rule card states one tool= one owner, both tools required to complete job, once tools are acquired they are with the job until completion.
Diagram values: ONE OWNER PER TOOL; COMPLETE ONLY WITH BOTH; KEEP TOOLS UNTIL COMPLETE
Robot: One owner for every tool.
Coral cart for job A need spanner S. Clamp T is free on the rack. No holding for job B.
Diagram values: S→A; T:FREE
Duck: My cart'll grab it for me.
Aqua cart for job B grabs T clamp. Job A still has S. No one has both tools.
Diagram values: A HOLDS S; B HOLDS T
Robot: The other cart is clamping in. Who's ready to go?
A circle of waiting
Job A: have spanner S, want clamp T. Job B: still have T. Job A: can't give S yet. Wait.
Diagram values: A WAITS FOR T; S→A; T→B
Duck: A needs it (the clamp) but B has it.
Job B is going to try and grab spanner S (still owned by A). So both jobs are now waiting for each other's tool.
Diagram values: B WAITS FOR S; S→A; T→B
Robot: B wants to borrow spanner from A. A has spanner.
A circular wait graph that looks like A->B->A. The carts retain their original tool. No repair work is complete.
Diagram values: A→B→A; NO JOB COMPLETE
Duck: One tool in every job that waits for the other.
Time goes on without any one's tool changing hands. The two carts are still stuck, under the same rules.
Diagram values: OWNERS UNCHANGED
Robot: The rules do not change, the longer you wait.
Duck explicitly breaks out and restores trial. Both carts put tools back on rack. S and T are free.
Diagram values: RESET TRIAL; S:FREE; T:FREE
Duck: Stop this test!
Agree on one order
New rule needs S before T on both jobs. Both tools are free to start in the new trial.
Diagram values: BOTH JOBS:S THEN T
Robot: New rule: Spanner comes first, then clamp for both jobs.
Job A picks S. Job B is waiting for S. Job B has nothing. Clamp T is still available on the rack.
Diagram values: A HOLDS S; B HOLDS NOTHING; T:FREE
Duck: A gets spanner. B has to wait. Can't take the clamp.
Job A will hold the free clamp T and S. It will repair. Job B is still holding nothing. A will hold the free T and keep S, and then will repair. B is still holding nothing.
Diagram values: A HOLDS S+T; A COMPLETE
Robot: Job A will hold the free clamp T and S. It will repair.
Job A. Put both of your tools back. Job B. Grab S then T. Fix it.
Diagram values: RELEASE S+T; B:S THEN T
Duck: A returns both of them and B picks them up in the same order.
The other cart goes first
New trial and you give priority to job B. Job A is empty, T is free, and usual priority is S->T.
Diagram values: B HOLDS S; A HOLDS NOTHING; T:FREE
Robot: New game. And now the first spanner goes to B.
Job A wants free T (doesn't have it yet). Job B still has S. What is the next step to respect the common order of the jobs?
Diagram values: BOTH JOBS:S THEN T
Duck: May A use clamp while waiting or is B next to use clamp?
Job B has clamp T and spanner S.
Diagram values: A WAITS EMPTY; B HOLDS S+T
Robot: A can't bypass spanner. B can grab the free clamp.
Job B complete, returns tools, both. Job A, picks up S then T. Completes repair. Returns both tools to rack.
Diagram values: B RELEASES BOTH; A:S THEN T; BOTH COMPLETE
Duck: B is complete. Place the tools back on the rack. Now A can be released.
Both repair pennants done; both tools available. Robot is aware of the difference between avoiding the two-tool circular wait, and the separate issue of fairness in turns.
Diagram values: THIS TWO-TOOL MODEL; FAIRNESS IS SEPARATE
Robot: But fair turns require different rules.
The lesson
In this two-tool approach every job must have exclusive access to spanner S and clamp T to complete. The tools are held until the job completes. So if job A has spanner S and is waiting for T, and job B has clamp T and is waiting for S, there is no way for either to complete under the given rules (it creates a circular wait). To help with this we explicitly clear out both tools to free state for the next attempt. If we insist that all jobs must get spanner S before clamp T, we break the circular wait. If a job is waiting on S, it isn't holding either tool so it can't interfere with the current S holder by holding T. A finite job that's allowed to run could get the free T tool and finish and give up both tools. This circular wait can be broken by consistent order of acquisition. Note that this doesn't guarantee fairness, bounded wait, no other kinds of deadlocks, or lack of starvation. The tools/jobs are simulations, not recommendations on safe physical machinery.
Try it
For a new try, two jobs must grab clamp T then spanner S. Same order, T then S. Job A has T. Job B has nothing. Spanner S is available. Can job B grab S while waiting for T? What job can next grab S? Why don't they have a two tool circular wait, with shared order.
Answer
B has to wait for T. Both jobs need to take T before S. So B can't bypass the first tool. A has T, so it can take the free S. If we let A run and its finite job is complete, it gives back T and S. Then B can take T, and then S. Because B has no tool A wants, there is no circular wait between these two jobs for this trial. The shared order doesn't ensure fair turns, nor does it avoid starvation.