Avoidance Strategy
Dynamically examine resource allocation state to ensure the system never enters an unsafe state that could lead to deadlock.
Safe State Concept
Definitions:
- Safe State: System can allocate resources to each transaction in some order and still avoid deadlock
- Unsafe State: No guarantee that deadlock can be avoided
- Key Point: Unsafe ≠ Deadlock, but unsafe state may lead to deadlock
Wait-Die and Wound-Wait Schemes (Detailed)
Wait-Die (Non-Preemptive)
Rule: Older transactions wait, younger transactions die
If Ti requests lock held by Tj:
If TS(Ti) < TS(Tj): // Ti is older
Ti WAITS for Tj
Else: // Ti is younger
ABORT Ti (Ti "dies")
Example: T1(TS=5) wants lock from T2(TS=10)
→ T1 is older, so T1 waits ✅
Example: T2(TS=10) wants lock from T1(TS=5)
→ T2 is younger, so T2 aborts ❌
Wound-Wait (Preemptive)
Rule: Older transactions wound (preempt) younger, younger wait for older
If Ti requests lock held by Tj:
If TS(Ti) < TS(Tj): // Ti is older
ABORT Tj (Ti "wounds" Tj)
Else: // Ti is younger
Ti WAITS for Tj
Example: T1(TS=5) wants lock from T2(TS=10)
→ T1 is older, so T2 is aborted (wounded) ❌
Example: T2(TS=10) wants lock from T1(TS=5)
→ T2 is younger, so T2 waits ✅
Comparison
| Aspect |
Wait-Die |
Wound-Wait |
| Type |
Non-preemptive |
Preemptive |
| Who Dies? |
Younger transaction |
Younger transaction |
| When? |
When younger requests lock |
When older requests lock |
| Rollbacks |
More frequent |
Less frequent |
Both schemes prevent deadlock by ensuring transactions only wait for older ones, eliminating circular wait!