Operation System
Operation System
Nim : 211011060083
MK : Sistem Operasi
Chapter 7: Deadlocks
Deadlock is a situation where requests cannot be executed by the scheduler because the
requests are waiting for each other. Deadlock is a major problem in sharing data.
System Model
o request
o use
o release
Deadlock Characterization
Resource-Allocation Graph
o R = {R1, R2, …, Rm}, the set consisting of all resource types in the system
• Pi requests instance of Rj
• Pi is holding an instance of Rj
Basic Facts
• Mutual Exclusion – not required for sharable resources (e.g., read-only files); must
hold for non-sharable resources
• Hold and Wait – must guarantee that whenever a process requests a resource, it
does not hold any other resources
o 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 allocated to it.
Deadlock Avoidance
• Simplest and most useful model requires that each process declare the maximum
number of resources of each type that it may need
• The deadlock-avoidance algorithm dynamically examines the resource-allocation
state to ensure that there can never be a circular-wait condition
• Resource-allocation state is defined by the number of available and allocated
resources, and the maximum demands of the processes
Basic Facts
Avoidance Algorithms
• Claim edge Pi → Rj indicated that process Pj may request resource Rj; represented by
a dashed line
• The request can be granted only if converting the request edge to an assignment
edge does not result in the formation of a cycle in the resource allocation graph
Banker’s Algorithm
• Multiple instances
• When a process gets all its resources it must return them in a finite amount of time
Data Structures for the Banker’s Algorithm
• Max: n x m matrix. If Max [i,j] = k, then process Pi may request at most k instances of
resource type Rj
Deadlock Detection
a. Work = Available
b. For i = 1,2, …, n, if Allocationi 0, then
Finish[i] = false; otherwise, Finish[i] = true
a. Finish[i] == false
b. Requesti Work
2. How long process has computed, and how much longer to completion
• Rollback – return to some safe state, restart process for that state
• Starvation – same process may always be picked as victim, include number of
rollback in cost factor