CSC264 · 2078 · 10 marks
How unsafe state differs from deadlocked state? Consider the following initial state and identify whether requested is granted or denied for the given cases. What will happen if process D requests 1 resource? What will happen if process A requests 1 resource? | Process | Has | Max | |---------|-----
How unsafe state differs from deadlocked state? Consider the following initial state and identify whether requested is granted or denied for the given cases. What will happen if process D requests 1 resource? What will happen if process A requests 1 resource?
| Process | Has | Max |
|---|---|---|
| A | 2 | 6 |
| B | 1 | 5 |
| C | 2 | 3 |
| D | 3 | 8 |
$$\text{Free} = 2$$
[10]
Unsafe State vs Deadlocked State, and Banker's Algorithm Application
Given Data
| Process | Has | Max | Need = Max − Has |
|---|---|---|---|
| A | 2 | 6 | 4 |
| B | 1 | 5 | 4 |
| C | 2 | 3 | 1 |
| D | 3 | 8 | 5 |
Free = 2
Total resources $= (2+1+2+3) + 2 = 10$ (single resource type).
Part 1: Unsafe State vs Deadlocked State
| Aspect | Unsafe State | Deadlocked State |
|---|---|---|
| Definition | No guaranteed safe sequence exists to let all processes finish | A set of processes is permanently blocked, each waiting on a resource held by another |
| Progress | Processes may still run; deadlock has not necessarily happened | No process can proceed at all |
| Nature | A warning/potential problem | An actual, current problem |
| Relationship | Superset: not every unsafe state leads to deadlock | A deadlocked state is always unsafe (deadlock ⊆ unsafe) |
| Handling | Banker's Algorithm avoids it by denying dangerous requests | Requires detection + recovery |
An unsafe state means the system might deadlock if unlucky future requests occur; a deadlocked state means it has already got stuck.
Part 2: Is the Initial State Safe?
Apply safety check with Free = 2. Look for a process with $\text{Need} \le \text{Free}$.
- C: Need = 1 ≤ 2 → run. Free = $2 + 2 = 4$
- A: Need = 4 ≤ 4 → run. Free = $4 + 2 = 6$
- B: Need = 4 ≤ 6 → run. Free = $6 + 1 = 7$
- D: Need = 5 ≤ 7 → run. Free = $7 + 3 = 10$
Safe sequence: C → A → B → D. The initial state is SAFE.
Part 3: Process D Requests 1 Resource
- Request = 1 ≤ Need(D) = 5 ✓
- Request = 1 ≤ Free = 2 ✓ (tentatively grant)
Tentative state: D: Has = 4, Need = 4. Free = $2 - 1 = 1$.
Safety check with Free = 1:
| Process | Need | Need ≤ Free? |
|---|---|---|
| A | 4 | No |
| B | 4 | No |
| C | 1 | Yes |
| D | 4 | No |
- Run C: Free = $1 + 2 = 3$
- Remaining A(4), B(4), D(4): none ≤ 3 → stuck
No safe sequence exists → UNSAFE state.
Conclusion: D's request is DENIED.
Part 4: Process A Requests 1 Resource
- Request = 1 ≤ Need(A) = 4 ✓
- Request = 1 ≤ Free = 2 ✓ (tentatively grant)
Tentative state: A: Has = 3, Need = 3. Free = $2 - 1 = 1$.
| Process | Has | Max | Need |
|---|---|---|---|
| A | 3 | 6 | 3 |
| B | 1 | 5 | 4 |
| C | 2 | 3 | 1 |
| D | 3 | 8 | 5 |
Safety check with Free = 1:
- C: Need = 1 ≤ 1 → run. Free = $1 + 2 = 3$
- A: Need = 3 ≤ 3 → run. Free = $3 + 3 = 6$
- B: Need = 4 ≤ 6 → run. Free = $6 + 1 = 7$
- D: Need = 5 ≤ 7 → run. Free = $7 + 3 = 10$
Safe sequence: C → A → B → D. The resulting state is SAFE.
Conclusion: A's request is GRANTED.
Summary
| Request | Result |
|---|---|
| Initial state | SAFE (C → A → B → D) |
| D requests 1 | DENIED (leads to unsafe state) |
| A requests 1 | GRANTED (state remains safe) |
Parts 2 and 3 give an initially safe state with D's request denied, and Part 4 shows that A's request is GRANTED.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.