 Permanent blocking of a set of processes that either
compete for system resources or communicate with each
other.
 No efficient solution.
 Involve conflicting needs for resources by two or more
processes.
 Deadlock occurs if each
process holds one resource and
requests the other.
 Used by only one process at a time and not
depleted by that use.
 Processes obtain resources that they later release
for reuse by other processes.
 EXAMPLE: Processors, I/O channels, main and
secondary memory, devices, and data structures
such as files, databases and semaphores.
Example of two processes competing for reusable resources
 Created (produced) and destroyed (consumed).
 EXAMPLE: Interrupts, signals, messages, and
information in
I/O buffers.
 Deadlock may occur if a Receive message is blocking.
 May take a rare combination of events to cause deadlock
EXAMPLE:
P1: receive(P2, M);
P2:receive(P1, M);
P1&P2:send
 Directed graph that depicts a state of the system
of resources and processes.
Mutual exclusion
 Only one process may use a resource at a time.
Hold-and-wait
 A process may hold allocated resources while a
waiting assignment of others.
No preemption
 No resource can be forcibly removed form a process
holding it.
Circular wait
 A closed chain of processes exists, such that each
process holds at least one resource needed by the
next process in the chain.
•Deadlock occurs if and only if the circular wait
condition is unresolvable.
•The circular wait condition is unresolvable when the
first 3 policy conditions hold.
•Thus the 4 conditions taken together constitute
necessary and sufficient conditions for deadlock.
 Deadlock Prevention.
 Deadlock Detection.
 Deadlock Avoidance.
 Integrated deadlock strategy.
Mutual Exclusion:
–Must be supported by the operating system.
Hold and Wait: Require a process request all resources at
onetime.
 Not efficient & difficult (cannot know in advance).
No Preemption: Process must release resource and request
again (priorities).
 Operating system may preempt a process to require it
releases its resources (handle same priorities).
Circular Wait: Define a linear ordering of resource types.
 Enforce requests only in one direction of the ordering
(either increasing or decreasing order).
 Resource access are granted to processes whenever
possible. The OS needs:
› an algorithm to check if deadlock is present.
› an algorithm to recover from deadlock.
 The deadlock check can be performed at every resource
request.
 Such frequent checks consume CPU time.
 A decision is made dynamically whether the current
resource allocation request will, if granted, potentially lead
to a deadlock.
 Requires knowledge of future process request.
Two Approaches to Deadlock Avoidance
 Do not start a process if its demands might lead to
deadlock.
 Do not grant an incremental resource request to a process
if this allocation might lead to deadlock.
 We can combine the previous approaches into the
following way:
› Group resources into a number of different classes and
order them.
› Use prevention of circular wait to prevent deadlock
between resource classes.
› Use the most appropriate approach for each class for
deadlocks within each class.
EXAMPLE:
 Swappable space: Blocking of memory on
secondary storage for use in swapping process.
 Process resources: Assignable devices, such as tape
drives and file.
 Main memory: Assignable in pages or segments to
processes.
• Internal resources: such as Input/output channels.
Deadlocks in operating system

Deadlocks in operating system

  • 2.
     Permanent blockingof a set of processes that either compete for system resources or communicate with each other.  No efficient solution.  Involve conflicting needs for resources by two or more processes.  Deadlock occurs if each process holds one resource and requests the other.
  • 6.
     Used byonly one process at a time and not depleted by that use.  Processes obtain resources that they later release for reuse by other processes.  EXAMPLE: Processors, I/O channels, main and secondary memory, devices, and data structures such as files, databases and semaphores.
  • 7.
    Example of twoprocesses competing for reusable resources
  • 8.
     Created (produced)and destroyed (consumed).  EXAMPLE: Interrupts, signals, messages, and information in I/O buffers.  Deadlock may occur if a Receive message is blocking.  May take a rare combination of events to cause deadlock EXAMPLE: P1: receive(P2, M); P2:receive(P1, M); P1&P2:send
  • 9.
     Directed graphthat depicts a state of the system of resources and processes.
  • 10.
    Mutual exclusion  Onlyone process may use a resource at a time. Hold-and-wait  A process may hold allocated resources while a waiting assignment of others. No preemption  No resource can be forcibly removed form a process holding it. Circular wait  A closed chain of processes exists, such that each process holds at least one resource needed by the next process in the chain.
  • 11.
    •Deadlock occurs ifand only if the circular wait condition is unresolvable. •The circular wait condition is unresolvable when the first 3 policy conditions hold. •Thus the 4 conditions taken together constitute necessary and sufficient conditions for deadlock.
  • 12.
     Deadlock Prevention. Deadlock Detection.  Deadlock Avoidance.  Integrated deadlock strategy.
  • 13.
    Mutual Exclusion: –Must besupported by the operating system. Hold and Wait: Require a process request all resources at onetime.  Not efficient & difficult (cannot know in advance). No Preemption: Process must release resource and request again (priorities).  Operating system may preempt a process to require it releases its resources (handle same priorities). Circular Wait: Define a linear ordering of resource types.  Enforce requests only in one direction of the ordering (either increasing or decreasing order).
  • 15.
     Resource accessare granted to processes whenever possible. The OS needs: › an algorithm to check if deadlock is present. › an algorithm to recover from deadlock.  The deadlock check can be performed at every resource request.  Such frequent checks consume CPU time.
  • 17.
     A decisionis made dynamically whether the current resource allocation request will, if granted, potentially lead to a deadlock.  Requires knowledge of future process request. Two Approaches to Deadlock Avoidance  Do not start a process if its demands might lead to deadlock.  Do not grant an incremental resource request to a process if this allocation might lead to deadlock.
  • 19.
     We cancombine the previous approaches into the following way: › Group resources into a number of different classes and order them. › Use prevention of circular wait to prevent deadlock between resource classes. › Use the most appropriate approach for each class for deadlocks within each class.
  • 20.
    EXAMPLE:  Swappable space:Blocking of memory on secondary storage for use in swapping process.  Process resources: Assignable devices, such as tape drives and file.  Main memory: Assignable in pages or segments to processes. • Internal resources: such as Input/output channels.