11-07-2012, 12:58 PM
Deadlocks
Deadlocks.ppt (Size: 459 KB / Downloads: 24)
The Deadlock Problem
A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.
Example
System has 2 tape drives.
P1 and P2 each hold one tape drive and each needs another one.
Bridge Crossing Example
Traffic only in one direction.
Each section of a bridge can be viewed as a resource.
If a deadlock occurs, it can be resolved if one car backs up (preempt resources and rollback).
Several cars may have to be backed up if a deadlock occurs.
Starvation is possible.
Deadlock Characterization
Mutual exclusion: only one process at a time can use a resource.
Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes.
No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task.
Circular wait: there exists a set {P0, P1, …, P0} of waiting processes such that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by
P2, …, Pn–1 is waiting for a resource that is held by Pn, and P0 is waiting for a resource that is held by P0.
Methods for Handling Deadlocks
Ensure that the system will never enter a deadlock state.
Allow the system to enter a deadlock state and then recover.
Ignore the problem and pretend that deadlocks never occur in the system; used by most operating systems, including UNIX.
Deadlock Prevention
Mutual Exclusion – not required for sharable resources; must hold for nonsharable resources.
Hold and Wait – must guarantee that whenever a process requests a resource, it does not hold any other resources.
Require process to request and be allocated all its resources before it begins execution, or allow process to request resources only when the process has none.
Low resource utilization; starvation possible.