Lab · Lecture 8
Deadlock lab
Two tools: the Banker's algorithm on editable matrices, and a resource-allocation graph you can draw and analyse.
- 1
Banker's tab: the slide example is loaded. Need is computed for you. Press Run safety algorithm and step through it with Next.
- 2
Use the Resource request panel to test a request. The three checks light up in order, exactly as you would write them in an exam.
- 3
Switch to the graph tab, load a preset or draw your own, and press Analyse to find cycles and decide whether they mean deadlock.
Try this first: run the safety algorithm on the slide example, then request (1,0,2) for P1 and see it granted, then (0,2,0) for P0 and see why it must wait.
State
Edit any cell. Need is computed as Max minus Allocation.
Allocation
| A | B | C | |
|---|---|---|---|
| P0 | |||
| P1 | |||
| P2 | |||
| P3 | |||
| P4 |
Max
| A | B | C | |
|---|---|---|---|
| P0 | |||
| P1 | |||
| P2 | |||
| P3 | |||
| P4 |
Need
| A | B | C | |
|---|---|---|---|
| P0 | 7 | 4 | 3 |
| P1 | 1 | 2 | 2 |
| P2 | 6 | 0 | 0 |
| P3 | 0 | 1 | 1 |
| P4 | 4 | 3 | 1 |
Available
| A | B | C |
|---|---|---|
Total instances (Allocation + Available)
| A | B | C |
|---|---|---|
| 10 | 5 | 7 |
Safety algorithm
Work starts as Available. Scan P0, P1, ... in order. A process whose Need fits in Work runs, finishes, and releases its Allocation into Work. Repeat until nothing runs.
Resource request
Three checks, in order. The third one pretends to grant and reruns the safety algorithm.
P0 Need (7,4,3), Available (3,3,2)