140 likes | 324 Views
Deadlocks. Deadlock handling . Deadlock prevention Deadlock avoidance Deadlock detection Deadlock recovery. How deadlocks arise. Conflicting need for resource by two or more processes All process are unable to proceed. Get A Get B Release B Release A. Get B Get A Release B
E N D
Deadlock handling • Deadlock prevention • Deadlock avoidance • Deadlock detection • Deadlock recovery
How deadlocks arise • Conflicting need for resource by two or more processes • All process are unable to proceed
Get A Get B Release B Release A Get B Get A Release B Release A Deadlock Example Precess P Process Q
Four conditions for deadlocks • Mutual exclusion of resources • Hold and wait • A process can hold a resource and wait for another • No preemption • A process will release resources voluntarily • Circular wait • There is a circular wait among the processes
Deadlock prevention • Make one of the four conditions false aways • No deadlock! • Which condition? Only circular wait condition is doable
Make circular wait condition false always • Order all the resources • Processes can request resources that are ordered strictly higher than what they are holding • Can prove that there are cycles in wait for graph
Deadlock avoidance • Allows more concurrency than prevention • A decision is made dynamically whether the current resource allocation request will potentially lead to a deadlock (if granted) • Needs knowledge of future resource needs
Two rules of deadlock avoidance • Do not start a process if its demands might lead to a deadlock • Do not grant an incremental resource request to a process if doing so might lead to a deadlock
Initial denial • R = (R1, R2, …, Rm) set of system resources; m types of resources • A = (V1, V2, …, Vm) available reources (not allocated to any process) at any time • Claim matrix; maximum requirement of each process for each resource • Current allocation matrix; what each process holds currently
Relations • Ri = Vi + sum(A_ki) k going from 1 to n • C_kl <= R_i for all k, I • A_ki <= C_ki for all k, i • (Strong condition): Start a new process P_n+1 only if R_I >= C_(n+1)i+sum(C_ki) k going from 1 to n; for all i
Resource allocation denial • Banker’s algorithm • Safe and unsafe states • Detect if a state is unsafe • Go from one safe state to another safe state
Deadlock recovery • Forcibly terminate some processes to recover from deadlocks. • Deadlock breaking set: Set of processes, which when terminated, will lead to the other processes’ normal termination. • Cost of forcibly terminating a process
Deadlock recovery Cont’d • Cost of deadlock breaking set: sum of the cost of aborting processes in the deadlock breaking set. • Optimal deadlock breaking set: Deadlock breaking set of least cost. • Finding the optimal deadlock breaking set is an NP-hard problem.