OPERATING SYSTEM deadlock prevention techniques

21 views 12 slides Apr 06, 2025
Slide 1
Slide 1 of 12
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12

About This Presentation

Operating System Deadlock Prevention: A Comprehensive Guide
Introduction
Operating systems (OS) are complex software systems responsible for managing hardware resources and providing an environment for application execution. One of the fundamental challenges in operating systems is ensuring efficien...


Slide Content

DEADLOCK
PREVENTION
OPERATING
SYSTEM
53-Akshay Vennikkal
54-Harsh Vishwakarma
55-Yash Vishwakarma
56-Anusha Yadav
#-Gracy Verma

Deadlock is a situation where a set of processes are
blocked because each process is holding a resource
and waiting for another resource acquired by some
other process.
Consider an example when two trains are coming
toward each other on the same track and there is only
one track, none of the trains can move once they are in
front of each other. A similar situation occurs in
operating systems when there are two or more
processes that hold some resources and wait for
resources held by other(s). For example, in the below
diagram, Process 1 is holding Resource 1 and waiting
for resource 2 which is acquired by process 2, and
process 2 is waiting for resource 1.
WHAT IS DEADLOCK?

HOLD AND
WAIT
MUTUAL
EXCLUSION
CIRCULAR
WAIT
NO
PREEMPTION
A process is holding at least
one resource and waiting for
resources.
Two or more resources are non-
shareable (Only one process
can use at a time)
A set of processes are waiting
for each other in circular form.
A resource cannot be taken
from a process unless the
process releases the resource.
DIFFERENT
CONDITIONS
WHEN
DEADLOCK
OCCUR

MUTUAL EXCLUSION
Mutual exclusion is a property of process
synchronization which states that “no
two processes can exist in the critical
section at any given point of time”. The
term was first coined by Dijkstra. Any
process synchronization technique being
used must satisfy the property of mutual
exclusion, without which it would not be
possible to get rid of a race condition.

If boy enters the room
then it will show occupied
and the girl won't be able
to enter that room.
After the boy is done he
will come out of that
room and the room will
again indicate vacant and
then the girl could use
the room.

To prevent this condition processes must be prevented from holding one or more resources while
simultaneously waiting for one or more others. There are several possibilities for this:
Require that all processes request all resources at one time. This can be wasteful of system resources
if a process needs one resource early in its execution and doesn't need some other resource until
much later.
Require that processes holding resources must release them before requesting new resources, and
then re-acquire the released resources along with the new ones in a single new request. This can be
a problem if a process has partially completed an operation using a resource and then fails to get it
re-allocated after releasing it.
Either of the methods described above can lead to starvation if a process requires one or more
popular resources.
HOLD AND WAIT

No Preemption means that a resource can only be free when the process holding it finishes
execution. If a process requests a resource that is already allocated to another process, the OS
frees all resources.
The preempted resources need the list of waiting resources for a process and the process
restarts only when it regains the old resource or the one that it is requesting. If the requested
resource is available, then it is immediately allocated to the process. If not available then the OS
releases the requesting resource from its current process and gives it to the requesting
process.
NO PREEMPTION

CIRCULAR WAIT
When a process waits for a resource held by
another process, which is also waiting for a
resource held by a third process, and so on, a
circular chain is created. This ordeal is known
as circular wait. It forms a circular loop where
it is necessary that every process requests
resources in increasing order of enumeration.
For example, Process A has Resource B but it
needs Resource A and requests it. Similarly,
another process, Process B has Resource A
but it is requesting Resource B. This situation
creates a circular wait loop.

METHODS OF HANDLING DEADLOCK
Deadlock prevention or
avoidance
Deadlock detection and
recovery
Ignore the problem
altogether
The idea is to not let the system
into a deadlock state.
One can zoom into each
category individually, Prevention
is done by negating one of
above mentioned necessary
conditions for deadlock
Let deadlock occur,
then do preemption
to handle it once
occurred.
If deadlock is very rare,
then let it happen and
reboot the system. This is
the approach that both
Windows and UNIX take.

The kernel does not avoid deadlocks of user-space locks (because often it
doesn't even know about them).
Deadlocks of kernel locks are avoided by writing code that is correct. This is
greatly helped by lockdep, which can prove the correctness of locking
operations.
(The lockdep code has been ported to user space, but it helps only for programs
that bother to use it.)
When the UI thread of an Android app is blocked for too long, an "Application
Not Responding" (ANR) error is triggered. If the app is in the foreground, the
system displays a dialog to the user, as shown in figure 1. The ANR dialog gives
the user the opportunity to force quit the app
ANR:
How does the linux kernel avoids deadlocks in user processes?

Advantageous to the processes that
perform a single burst of activity.
No preemption is required.
Convenient to apply to resources that
can save and restore their states
easily.
Compile-time checks help apply it
feasibly
The system design solves problems so
no run-time computation is required.
Advantages of Deadlock Disadvantages of Deadlock
Delay in process initiation.
Knowledge of future resources is
necessary.
Frequent preemptions.
Doesn’t allow incremental
resource requests.
There are inherent preemption
losses.