deadlocks
DESCRIPTION
Deadlocks. CS 3060. Imagine a narrow set of stairs, only wide enough for one person to pass. However, the landings are big enough for several people to stand. Wait. Deadlock. Preemptable and Non-preemptable Resources. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/1.jpg)
Deadlocks
CS 3060
![Page 2: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/2.jpg)
Imagine a narrow set of stairs, only wide enough for one person to pass.
However, the landings are big enough for several people to stand.
![Page 3: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/3.jpg)
Wait
![Page 4: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/4.jpg)
Deadlock
![Page 5: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/5.jpg)
Preemptable and Non-preemptable Resources
A preemptable resource is one that can be temporarily taken way from the process owning it without any ill effects.
A non-preemptable resource is one that cannot be taken away without causing the computation to fail.
![Page 6: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/6.jpg)
Using Semaphores to Acquire and Use a Resource
wait(&semaphore_1); use_resource_1; signal(&semaphore_1)
![Page 7: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/7.jpg)
Using Semaphores to Acquire and Use Two Resources
wait(&semaphore_1); wait(&semaphore_2); use_resource_1; use resource_2; signal(&semaphore_2); signal(&semaphore_1)
![Page 8: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/8.jpg)
Two Processes Using Semaphores to Acquire and Use Two Resources
wait(&semaphore_1); wait(&semaphore_2); use_resource_1; use resource_2; signal(&semaphore_2); signal(&semaphore_1)
wait(&semaphore_2); wait(&semaphore_1); use_resource_1; use resource_2; signal(&semaphore_1); signal(&semaphore_2)
Process A Process B
![Page 9: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/9.jpg)
wait(&semaphore_1); wait(&semaphore_2); use_resource_1; use resource_2; signal(&semaphore_2); signal(&semaphore_1)
wait(&semaphore_2); wait(&semaphore_1); use_resource_1; use resource_2; signal(&semaphore_1); signal(&semaphore_2)
Process A Process B
1 10
Time slice expires…
semaphore 1 semaphore 2
Two Processes Using Semaphores to Acquire and Use Two Resources
![Page 10: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/10.jpg)
wait(&semaphore_1); wait(&semaphore_2); use_resource_1; use resource_2; signal(&semaphore_2); signal(&semaphore_1)
wait(&semaphore_2); wait(&semaphore_1); use_resource_1; use resource_2; signal(&semaphore_1); signal(&semaphore_2)
Process A Process B
10 0D E A D L O C K !
semaphore 1 semaphore 2
Two Processes Using Semaphores to Acquire and Use Two Resources
![Page 11: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/11.jpg)
wait(&semaphore_1); wait(&semaphore_2); use_resource_1; use resource_2; signal(&semaphore_2); signal(&semaphore_1)
wait(&semaphore_2); wait(&semaphore_1); use_resource_1; use resource_2; signal(&semaphore_1); signal(&semaphore_2)
Process A Process B
Can you fix it so no deadlock occurs?
Two Processes Using Semaphores to Acquire and Use Two Resources
![Page 12: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/12.jpg)
wait(&semaphore_1); wait(&semaphore_2); use_resource_1; use resource_2; signal(&semaphore_2); signal(&semaphore_1)
wait(&semaphore_1); wait(&semaphore_2); use_resource_1; use resource_2; signal(&semaphore_2); signal(&semaphore_1)
Process A Process B
Two Processes Using Semaphores to Acquire and Use Two Resources
![Page 13: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/13.jpg)
Some Examples of Deadlock
![Page 14: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/14.jpg)
Some Examples of DeadlockDeadlock on a file request
A System built for contractors has two files (among others) - one for suppliers - one for inventory
It also has two applications (among others) - a purchasing application that orders material - a sales application that creates a supply list
![Page 15: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/15.jpg)
Some Examples of DeadlockDeadlock on a file request
Inventory Suppliers
Purchasing
Sales
Purchasing accesses thesupplier file to place anorder for lumber.
Sales accesses theinventory file to reserve parts to builda home ordered today.
Purchasing now tries toaccess the Inventory fileto verify the quantity of lumber on hand before placing the order
Sales tries to access the supplier file to check the schedule of a subcontractor.
![Page 16: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/16.jpg)
Some Examples of DeadlockDeadlock on a print spooler
A print spooler accepts input from many users, but will notstart a print job until it has a complete print file.
spool
print job
print jobThe day that a big project is due everyonein class submits their print files at the sametime. The spooler accepts pages from everyoneso several page ones show up, then several page twos, and so on. Quickly the spool filefills. It cannot print anything because is hasno complete jobs.
![Page 17: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/17.jpg)
Four Conditions for Deadlock
1. Mutual exclusion condition: Each resource is either being used by exactly one process or it is available.
2. Hold and wait condition: Processes currently holding resources granted earlier can request additional new resources.
3. No preemption condition: Resources previously granted cannot be taken away from the process. The process must release them voluntarily. Once a process requests a resource that is not available, it cannot withdraw its request.
4. Circular wait condition: There must be a circular chain of two or more processes, each of which is waiting for a resource held by the next member of the chain.
![Page 18: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/18.jpg)
Deadlock Modeling
process
resource
The resource hasbeen assigned tothe process.
resource
process
The process isblocked, waitingfor the resource.
This is called a Resource Graph
![Page 19: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/19.jpg)
Deadlock Modelingprocess
resource resource
process
r1 r2
p1
p2
process p1 ownsresource r1
process p1 is blockedwaiting for resource r2
process p2 is blockedwaiting for resource r1
process p2 ownsresource 2
Circular Wait Condition!
![Page 20: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/20.jpg)
This Process-Resource model provides a “snapshot” of the relationships between processes and resources at some instant in time.
We need a model that addresses the dynamics of the relationships … i.e. what happens over time.
![Page 21: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/21.jpg)
S is the set of states {si}
where each state s is represented with a resourcegraph representing the processes and resourcesin the machine.
The initial state, s0, represents the situationWhere none of the resources have been allocated.
In this model we are interested in state transitions.The pattern in which resources are requested,allocated, and released will determine whether or not the system is deadlocked.
![Page 22: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/22.jpg)
Process A
Request resource RRequest resource SDo some workRelease resource RRelease resource S
Process B
Request resource SRequest resource TDo some workRelease resource SRelease resource T
Process C
Request resource TRequest resource RDo some workRelease resource TRelease resource R
Assume a Round Robin Scheduling AlgorithmWith events occurring in the following order:
Process A requests resource RProcess B requests resource SProcess C requests resource TProcess A requests resource SProcess B requests resource TProcess C requests resource R
![Page 23: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/23.jpg)
Process A requests resource RProcess B requests resource SProcess C requests resource TProcess A requests resource SProcess B requests resource TProcess C requests resource R
A B C
R S T
![Page 24: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/24.jpg)
Process A requests resource RProcess B requests resource SProcess C requests resource TProcess A requests resource SProcess B requests resource TProcess C requests resource R
A B C
R S T
![Page 25: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/25.jpg)
Process A requests resource RProcess B requests resource SProcess C requests resource TProcess A requests resource SProcess B requests resource TProcess C requests resource R
A B C
R S T
![Page 26: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/26.jpg)
Process A requests resource RProcess B requests resource SProcess C requests resource TProcess A requests resource SProcess B requests resource TProcess C requests resource R
A B C
R S T
![Page 27: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/27.jpg)
Process A requests resource RProcess B requests resource SProcess C requests resource TProcess A requests resource SProcess B requests resource TProcess C requests resource R
A B C
R S T
![Page 28: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/28.jpg)
Process A requests resource RProcess B requests resource SProcess C requests resource TProcess A requests resource SProcess B requests resource TProcess C requests resource R
A B C
R S T
D E A D L O C K !
![Page 29: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/29.jpg)
We know that the operating system is not bound torun processes in any particular order. In this case, ifthe operating system knew of the impending deadlock,it could have scheduled the work differently!
![Page 30: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/30.jpg)
Process A requests resource RProcess B requests resource SProcess C requests resource TProcess A requests resource SProcess B requests resource TProcess C requests resource R
A B C
R S T
![Page 31: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/31.jpg)
Process A requests resource RProcess B requests resource SProcess C requests resource TProcess A requests resource SProcess B requests resource TProcess C requests resource R
A B C
R S T
potential deadlock – block this call!
![Page 32: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/32.jpg)
Process A requests resource RProcess B requests resource SProcess C requests resource TProcess A requests resource SProcess B requests resource TProcess C requests resource R
A B C
R S T
potential deadlock – block this call!
![Page 33: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/33.jpg)
Process A requests resource RProcess B requests resource SProcess C requests resource TProcess A requests resource SProcess B requests resource TProcess C requests resource R
A B C
R S T
potential deadlock – block this call!
![Page 34: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/34.jpg)
Process A requests resource RProcess B requests resource SProcess C requests resource TProcess A requests resource SProcess B requests resource TProcess C requests resource R
A B C
R S T
potential deadlock – block this call!
Blocked.
blocks
![Page 35: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/35.jpg)
Process A requests resource RProcess B requests resource SProcess C requests resource TProcess A requests resource SProcess B requests resource TProcess C requests resource RProcess A does its workProcess A releases resource RProcess A releases resource S
A B C
R S T
potential deadlock – block this call!
Blocked.
blocks
There is no deadlock ---Process C does its work and releases its resourcesProcess B is now unblocked
![Page 36: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/36.jpg)
Deadlock Strategies
The Ostrich Algorithm:Ignore the problem. If you ignore it, it may ignore you.
Detection and Recovery:Let deadlocks occur, detect them and take action.
Dynamic avoidance:OS is careful how it allocates resources
Deadlock Prevention:Structurally negate one of the conditions necessary tocause deadlock.
![Page 37: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/37.jpg)
The Ostrich AlgorithmGood or Bad?
Many potential deadlock situations occur because almost allresources on a system are finite.
For example, The number of open files that a system can manageis limited by the size of the i-node table. Suppose that 100 processes all require 100 open files before they can do their work. After each has opened 99, the i-node table becomes full. Now, none of the processes can open another file and a deadlock occurs.
How often will this situation occur?Does it occur often enough that it is worth fixing?Fixing such problems is expensive and usually involvesplacing inconvenient restrictions in what a process can do.
![Page 38: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/38.jpg)
Reminder
process
resource
The resource hasbeen assigned tothe process.
resource
process
The process isblocked, waitingfor the resource.
![Page 39: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/39.jpg)
Deadlock Detection Is there a deadlock in the drawing below?
A
F
C
R
S
W
D
B
E
G
T
U WCycles are pretty easy tofind with visual inspection.Can they be found algorithmically?
![Page 40: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/40.jpg)
Resource graphs are an example of a directed graph.many algorithms exist to detect cycles in a directed graph.
Repeat the following steps for each node in the graph
1. Initialize a list to the empty list. Designate all arcs as unvisited
2. Add the current node to the list. Check to see if the node appears in the list more than once. If it does a cycle exists.
3. From the given node, see if there are any outgoing arcs. If so, go to step 4. Otherwise go to step 5.
4. Pick one of the outgoing nodes at random and mark it. Follow it to the new current node and go to step 2.
5. Dead end. Remove the node from the list and go back to the previous one and make it the current node. Go to step 3. If this node is the initial node, there are no cycles.
![Page 41: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/41.jpg)
Deadlock Detection Is there a deadlock in the drawing below?
A
F
C
R
S
W
D
B
E
G
T
U W
Start here andgo left to right,top to bottom
![Page 42: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/42.jpg)
A
F
C
R
S
W
D
B
E
G
T
U W
List L
R
![Page 43: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/43.jpg)
A
F
C
R
S
W
D
B
E
G
T
U W
List L
R
This is the onlyoutging arc, so A is the next node
A
x
![Page 44: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/44.jpg)
A
F
C
R
S
W
D
B
E
G
T
U W
List L
R
This is the onlyoutging arc, so S is the next node
A
S
x
x
![Page 45: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/45.jpg)
A
F
C
R
S
W
D
B
E
G
T
U W
List L
R
S has no outgoingArcs, so back-upTo A
A
x
x
![Page 46: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/46.jpg)
A
F
C
R
S
W
D
B
E
G
T
U W
List L
R
A has no unmarked outgoing arcs, so back-up To R
x
x
![Page 47: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/47.jpg)
A
F
C
R
S
W
D
B
E
G
T
U W
List L
R has no unmarked outgoing arcs, so we are done inspectingthis node.
x
x
![Page 48: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/48.jpg)
A
F
C
R
S
W
D
B
E
G
T
U W
List L
Move to the next nodeand repeat the algorithm.
It should be pretty obviousthat this iteration stops quickly, finding no cycle.
![Page 49: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/49.jpg)
A
F
C
R
S
W
D
B
E
G
T
U W
List L
Move to the next nodeand repeat the algorithm.
![Page 50: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/50.jpg)
A
F
C
R
S
W
D
B
E
G
T
U W
List L
BxThis is the only
outgoing arcT
![Page 51: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/51.jpg)
A
F
C
R
S
W
D
B
E
G
T
U W
List L
Bx This is the only
outgoing arcTx
![Page 52: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/52.jpg)
A
F
C
R
S
W
D
B
E
G
T
U W
List L
Until finally at this point we have …
x
x
x
x
x
x
B
T
E
W
G
U
D
![Page 53: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/53.jpg)
A
F
C
R
S
W
D
B
E
G
T
U W
List L
If we go this way we hit adead end … there are nooutgoing arcs
x
x
x
x
x
x
B
T
E
W
G
U
D
![Page 54: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/54.jpg)
A
F
C
R
S
W
D
B
E
G
T
U W
List L
So we back up and look atthe only unmarked arcfrom D.
x
x
x
x
x
x
B
T
E
W
G
U
D
x
![Page 55: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/55.jpg)
A
F
C
R
S
W
D
B
E
G
T
U W
List L
At this point, T gets added to the list.When the list is inspected, we note that it isin the list twice. Therefore a cycle exists.
x
x
x
x
x
x
B
T
E
W
G
U
D
T
x
![Page 56: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/56.jpg)
Deadlock Modeling
process
resource
The resource hasbeen assigned tothe process.
resource
process
The process isblocked, waitingfor the resource.
One way to model “units” of a resource is like this …
This resource has 2 unitsthat can be assigned.
![Page 57: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/57.jpg)
Graph ReductionGiven a directed resource graph
1. Find a process that is currently using a resource and not waiting for one. This process can be removed from the graph. This is because the process would eventually finish and its resources returns to the pool of available resources.
2. Find a process that’s only waiting for resource classes that aren’t fully allocated. This process isn’t contributing to deadlock since it will eventually get its resources and finish. Then its resources can be returned to the available pool.
3. Go back to step 1 until all possible connections have been removed.
If there are any connections between processes and resources leftWhen you are done, then the system will deadlock.
![Page 58: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/58.jpg)
Deadlock Prevention
Note that Deadlock prevention is different from detection.
![Page 59: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/59.jpg)
1. Mutual exclusion condition: Each resource is either being used by exactly one process or it is available.2. Hold and wait condition: Processes currently holding resources granted earlier can request additional new resources.3. No preemption condition: Resources previously granted cannot be taken away from the process. The process must release them voluntarily. Once a process requests a resource that is not available, it cannot withdraw its request.4. Circular wait condition: There must be a circular chain of two or more processes, each of which is waiting for a resource held by the next member of the chain.
For deadlock to occur, all of the following conditions must hold.
Deadlock prevention schemes all try to make sure that at least oneof these conditions is not true.
![Page 60: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/60.jpg)
Attacking the Mutual Exclusion Condition
If no resource were ever assigned exclusively to a singleprocess, then there would be no deadlock problems.
Is this reasonable?
How might you avoid mutual exclusion on a printer?
It is difficult to avoid mutual exclusion. However, you canavoid assigning a resource unless and until it isabsolutely necessary. Try to make sure that as fewprocesses as possible can lay claim to the resource.
![Page 61: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/61.jpg)
Attacking the Hold and Wait Condition
1. Require a process to request all of its resources when it is first created.
This would be impossible for an interactive system. However, a batch system could do this … only add a job to the ready list when all of the resources it needs are available. But, is there a problem?Poor utilization of resources !
2. Require a process to give up all resources it has allocated to it, before it can request any new ones.
This is okay for interactive systems, but it forces a process to compete for all resources, even when it needs an incremental resource.
![Page 62: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/62.jpg)
Attacking the No Preemption Condition
This is not very promising … it is difficult to take a resourceaway from a process until the process has finished with it.
![Page 63: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/63.jpg)
Attacking the Circular Wait Condition
There are two possible approaches:
Only allow a process to have one resource at a time.
Provide a global numbering system for resources. A processmay have as many resources as it wants, but requests must bein numerical order. For example, a process may request a printerand then a plotter, but never a plotter and then a printer!
![Page 64: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/64.jpg)
Deadlock Avoidance
Deadlock avoidance schemes control state transitions. They will only allow transitions due to allocations, when they can be certain that a deadlock cannot occur due to subsequent requests.
![Page 65: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/65.jpg)
The Banker’s AlgorithmThe Banker’s algorithm was developed by Dijkstra in 1965and provides a scheduling algorithm that can avoid deadlocks.It is modeled on the way a small town banker might deal witha group of customers to whom he has granted lines of credit.
If granting a request leads to a safe state, the request isgranted. If it does not, the request is denied. When arequest is denied the customer may come back laterto make the request again.
![Page 66: Deadlocks](https://reader035.vdocument.in/reader035/viewer/2022070421/56816144550346895dd0bd93/html5/thumbnails/66.jpg)
Dijkstra’s algorithm is elegant in concept, but is almost useless in practice.Why?
1. It requires a process to know in advance what its maximumresource needs will be.
2. It assumes that the number of available resources is constantso does not account for failures.
3. It assumes that the number of processes is constant so does not account for users logging in and out of a system.