Demo: A Deadlock¶
Two accounts, each with a lock; one thread transfers from a to b, the other from b to a.
Run¶
In a second terminal, while it sits there:
Stop it with Ctrl+C, then:
To see who holds what: gdb ./deadlock, run, Ctrl+C, thread apply all bt 4.
Ask¶
- What state are the threads in, and how much CPU do they use? Is the program running?
- Which lock does each thread hold, and which is it waiting for?
orderedtakes the same two locks. What does it do differently?