Deadlocks - PowerPoint PPT Presentation

About This Presentation
Title:

Deadlocks

Description:

In normal conditions, process can utilise a ... No preemption ... No Preemption Preempt. Borrow resources held by other processes (not always possible, eg. ... – PowerPoint PPT presentation

Number of Views:62
Avg rating:3.0/5.0
Slides: 18
Provided by: angel115
Category:

less

Transcript and Presenter's Notes

Title: Deadlocks


1
Deadlocks
2
Introduction
  • A deadlock is a state of CS (computer system)
    when all processes are waiting to get out of WAIT
    state, while holding resources and by doing that
    preventing other processes to get out of their
    WAIT states

3
Deadlocks
4
Utilisation of Resources
  • In normal conditions, process can utilise a
    resource by
  • Request (if resource is used by a different
    process, if must WAIT)
  • Use
  • Release

5
Deadlock Creation
  • Deadlocks can arise if the following conditions
    are met simultaneously
  • Mutual exclusion
  • At lease one resource must be non-sharable, so
    that only one process can use it at any time
  • Hold and wait
  • There must be a process that holds at least one
    resource and waits for more resources that are
    held by other processes

6
Deadlock Creation continued
  • No preemption
  • Resource can only be released by the process
    holding it when the process completes its task
  • Circular wait
  • There must exist a set of processes that hold and
    wait for more resources which form a cyclic loop
  • Example (two processes P1 P2, two resources R1
    R2)
  • P1 holds R2 and waits for R1
  • P2 holds R1 and waits for R2

P1
P2
R2
R1
7
Resource Allocation Graphs
  • In order to analyse deadlocks and how they arise,
    we can draw graphs indicating resources and
    processes, and their relationship
  • Processes are drawn as circles
  • Resources are in boxes

8
Resource Allocation Graphs
R1
R3
P1
P2
P3
R2
R4
9
Resource Allocation Graphs
  • Graphs components are divided into three sets
  • Processes, P P1, P2, P3
  • Resources, R R1, R2, R3, R4
  • Edges, E P1 ? R1, P2 ? R3, R1 ? P2, R2 ? P2,
    R2 ? P1, R3 ? P3
  • Where R11, R22, R31, R44 are instances of
    resources

10
Deadlock
R1
R3
P1
P2
P3
R2
R4
11
Handling Deadlocks
  • There are three methods used for dealing with
    deadlocks
  • Prevention allocate resources in such a way
    that deadlocks cannot possibly occur
  • Avoidance allow deadlocks and when detected,
    recover
  • Ignore allow process starvation, and forget
    that it ever happened. This approach is used by
    most operating systems including UNIX

12
Deadlock Prevention
  • Allocate resources such that preconditions are
    not possible
  • Mutual Exclusion shared resources means
    deadlock not possible (but cannot share all
    resources, eg. printers)
  • Hold and Wait make processes allocate resources
    first and then execute

13
Deadlock Prevention continued
  • No Preemption Preempt. Borrow resources held by
    other processes (not always possible, eg.
    printers)
  • Circular Wait impose a total ordering of
    resource types and require that each process
    requests resources in an increasing order of
    enumerations

14
Deadlock Avoidance
  • In avoiding deadlocks we must use an algorithm to
    find out how to allocate resources
  • If we have a resource allocation system with only
    one instance of each resource, we can use the
    Resource Allocation Graph
  • A much better alternative is the Bankers Algorithm

15
Bankers Algorithm
  • Bankers algorithm is based on the idea of a
    banking system that ensures that the bank never
    allocates its available cash
  • Each process must declare the maximum number of
    instances of each resource it will need

16
Bankers Algorithm continued
  • When a resource is requested, the system must
    make sure that after the allocation it will
    remain in a safe state
  • A safe state is a state in such a deadlock is not
    possible

17
Exercises
  • Analyse the following system
  • Processes, P P1, P2, P3 , P4
  • Resources, R R1, R2
  • Edges, E P1 ? R1, P3 ? R2, R1 ? P2, R1 ? P3,
    R2 ? P1 , R2 ? P4
  • Where R12, R22 are instances of resources
Write a Comment
User Comments (0)
About PowerShow.com