0% found this document useful (0 votes)
21 views

UNIT-2 Deadlock Avoidance

Uploaded by

targetappcraft
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

UNIT-2 Deadlock Avoidance

Uploaded by

targetappcraft
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Deadlock Avoidance

Deadlock Prevention Limitations


• Deadlock prevention emphasis on that, at
least one of the necessary conditions for
deadlock cannot occur and, hence, that
deadlocks cannot hold.

• Low device utilization and reduced system


throughput
Deadlock Avoidance
• A deadlock-avoidance algorithm dynamically examines the
resource-allocation state to ensure that a circular wait
condition can never exist.

• Resource-allocation state is defined by the number of


available and allocated resources, and the maximum
demands of the processes

• Each process declare the maximum number of resources of


each type that it may need. Given this a priori information, it
is possible to construct an algorithm that ensures that the
system will never enter a deadlocked state.
Safe State
• A state is safe if the system can allocate resources to each
process (up to its maximum) in some order and still avoid a
deadlock.

• A system is in a safe state only if there exists a safe sequence

• System is in safe state if there exists a sequence <P1, P2, …,


Pn> of ALL the processes in the systems such that for each Pi,
the resources that Pi can still request can be satisfied by
currently available resources + resources held by all the Pj,
with j < I
Safe, Unsafe, Deadlock State
Avoidance algorithms
Avoidance algorithms
• Avoidance algorithms that ensure that the
system will never deadlock

• Whenever a process requests a resource that


is currently available, the system must decide
whether the resource can be allocated
immediately or whether the process must
wait. The request is granted only if the
allocation leaves the system in a safe state.
Resource-Allocation Graph

p R

p R

p R

 Before process Pi starts executing, all its claim edges must already appear in the
resource-allocation graph.
Detection Algorithm
Example
Example-II
Detection-Algorithm Usage
How often is a deadlock likely to occur?

1) If deadlocks occur frequently, then the detection algorithm


should be invoked frequently.

2) we can invoke the deadlock detection algorithm


every time a request for allocation cannot be
granted immediately.

3) Once per hour or whenever CPU utilization drops


below 40 percent
Recovery from Deadlock
When a detection algorithm determines that a
deadlock exists, several alternatives are available.

1) Deal with the deadlock manually


2) Recover from the deadlock automatically
• Abort one or more processes
• Preempt some resources
Recovery from Deadlock: Process
Termination
Recovery from Deadlock: Resource
Preemption!
To eliminate deadlocks using resource preemption, we successively
preempt some resources from processes and give these resources to
other processes until the deadlock cycle is broken.

You might also like