SLIDE 13 CPSC-410/611 Operating Systems Deadlocks 13
Deadlock Detection & Recovery
- Deadlock prevention and avoidance are cautious approaches.
May overly reduce resource utilization.
- Alternative: Periodically analyze RAG, detect deadlocks, and
initiate recovery.
– A priori knowledge of resource requirements not needed. – Higher resource utilization
– Cost of recovery
Multiple-Unit Resources
int available[m]; /* resources available */ int alloci[m]; /* resources allocated to Pi */ int rec_veci[m]; /* currently requested by Pi */ int temp_av[m] = available; bool finish[n] = (FALSE, ..., FALSE); bool found = TRUE; for (i=0, i<n, i++) if (rec_veci == (0,...,0)) finish[i] = TRUE; while(found) { found = FALSE; for(i=0, (i<n) && (!found), i++) { if ((!finish[i]) && (req_veci < temp_av)) /* assume Pi runs to completion */ {temp_av += alloci; finish[i]=TRUE; found=TRUE;} } } /* for any finish[i] == FALSE, Pi is deadlocked */