Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 13

Principles of Programming Languages

Deadlocks

By:
Submitted to: 05-CSEA- Abhinav
Ms. Preeti Arora 22-CSEA-Deepak
Assistant Professor 25-CSEA-Gitika Chopra
Department of Computer Science and Engg. 34-CSEA-Jatin Bhatnagar
What is a Deadlock ?

• 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.
Realtime Example of
Deadlock

• 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.
Deadlock Situation in
Database

• No Two Transactions takes place at a


time in the Database. It hold one
transaction In the Queue to Proceed.
Conditions for Deadlock

• What are the conditions that a Process


Undergone Deadlock situation.
• How can we Identify that a Process is in
Deadlock Situation ?
• When a process is accessing a

Mutual-Exclusion shared variable, the process is said


to be in a CRITICAL SITUATION
• One process at a time can use a
resource.

• A process holding at least one


resource is waiting to acquire
additional resources held by another Hold and Wait
processes.
• Printer needs scanned copy to print
and scanner wants a copy to scan.
• A Resource can be released only
voluntarily by the process holding it,
No Preemption after that process has completed its
task.
• Number of resources can be
feasibly removed from a processor
holding it.

• There exists a set { p1,p2,p3…,pn } of


waiting processes such that p1 is
waiting for a resource that Is held by Circular Wait
p2, p2 is waiting for a resource that
is held by p3.
• Pn is waiting for the resource pn-1
Methods of Handling
Deadlocks
Deadlock Prevention

• This is done by restraining the ways a


request can be made. Since deadlock
occurs when all the above four
conditions are met, we try to prevent any
one of them, thus preventing a deadlock.
Deadlock Avoidance

• In deadlock avoidance, the operating


system checks whether the system is in
safe state or in unsafe state at every
step which the operating system
performs.
• The process continues until the system
is in safe state. Once the system moves
to unsafe state, the OS has to backtrack
one step
Deadlock Detection And
Recovery

• This approach let the processes fall in


deadlock and then periodically check
whether deadlock occur in the system or
not.
• If it occurs then it applies some of the
recovery methods to the system to get
rid of deadlock.
Deadlock Ignorance

• Deadlock Ignorance is the most widely


used approach among all the
mechanism.
• This is being used by many operating
systems mainly for end user uses. In
this approach, the Operating system
assumes that deadlock never occurs.
• It simply ignores deadlock.

You might also like