Deadlock and starvation - PowerPoint PPT Presentation

1 / 32
About This Presentation
Title:

Deadlock and starvation

Description:

Space is available for allocation of 200K bytes, and the following sequence of events occur ... The first process in the sequence can finish, because even if it ... – PowerPoint PPT presentation

Number of Views:95
Avg rating:3.0/5.0
Slides: 33
Provided by: debora71
Category:

less

Transcript and Presenter's Notes

Title: Deadlock and starvation


1
Deadlock and starvation
  • CS3450
  • Chapter 6

2
Deadlock
  • Permanent blocking of a set of processes that
    either compete for system resources or
    communicate with each other
  • Involve conflicting needs for resources by two or
    more processes

3
Reusable Resources
  • Used by one process at a time and not depleted by
    that use
  • Processes obtain resources that they later
    release for reuse by other processes
  • Processor time, I/O channels, main and secondary
    memory, files, databases, and semaphores
  • Deadlock occurs if each process holds one
    resource and requests the other

4
Resource Examples
  • Resource Serially Reusable?
    Non-preemptable?
  • (only one process at a time)
    (take away harm)

CPU
read-only database
printer
Semaphore
5
Example of Deadlock
  • Space is available for allocation of 200K bytes,
    and the following sequence of events occur
  • Deadlock occurs if both processes progress to
    their second request

P1
P2
. . .
. . .
Request 80K bytes
Request 70K bytes
. . .
. . .
Request 60K bytes
Request 80K bytes
6
Consumable Resources
  • Created (produced) and destroyed (consumed) by a
    process
  • 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

P1
. . .
Recieve (P2)
. . .
Send (P2)
P2
. . .
Recieve (P1)
. . .
Send (P1)
7
Conditions for Deadlock
  • Mutual exclusion
  • only one process may use a resource at a time
  • Hold-and-wait
  • a process may hold allocated resources while
    awaiting assignment of others
  • No preemption
  • no resource can be forcibly removed from a
    process holding it

8
Conditions for Deadlock
  • 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
  • consequence of the first three conditions
  • Other conditions are necessary but not sufficient
    for deadlock

9
Circular Wait
Held by
Requests
Process P1
Process P2
Requests
Held By
10
Deadlocked?
11
Deadlocked?
1 resource remains
12

Deadlocked?

0 resource remains
13

Deadlocked?

0 resource remains
14
Deadlocked?
15
Deadlock Prevention
  • Mutual Exclusion
  • usually cannot be disallowed
  • Hold-and-Wait
  • require that a process request all its required
    resources at one time
  • block the process until all requests can be
    granted simultaneously
  • process may be held up for a long time waiting
    for all its requests
  • resources allocated to a process may remain
    unused for a long time. These resources could be
    used by other processes

16
Deadlock Prevention
  • No preemption
  • if a process is denied a further request, the
    process must release the original resources
  • if a process cannot obtain a resource, the
    process may have to release its resources. Must
    have capability to restore to current state.
  • practical only only when the state can be easily
    saved and restored later, such as the processor.

17
Deadlock Prevention
  • Circular wait
  • define a linear ordering for resources
  • once a resource is obtained, only those resources
    higher in the list can be obtained
  • may deny resources unnecessarily

18
Deadlock Detection
  • Operating system checks for deadlock
  • Check at resource request
  • early detection of deadlock
  • frequent checks consume processor time
  • Check periodically

19
Deadlock Avoidance(an algorithm that prevents
deadlock)
  • 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
  • Not necessary to preempt and rollback processes

20
Deadlock Avoidance
  • Maximum resource requirement must be stated in
    advance
  • Processes under consideration must be
    independent no synchronization requirements
  • There must be a fixed number of resources to
    allocate
  • No process may exit while holding resources

21
Strategies once Deadlock Detected
  • Abort all deadlocked processes
  • Back up each deadlocked process to some
    previously defined checkpoint, and restart all
    process
  • original deadlock may occur
  • Successively abort deadlocked processes until
    deadlock no longer exists
  • Successively preempt resources until deadlock no
    longer exists

22
Selection Criteria Deadlocked Processes
  • Least amount of processor time consumed so far
  • Least number of lines of output produced so far
  • Most estimated time remaining
  • Least total resources allocated so far
  • Lowest priority

23
Deadlock Avoidance Algorithms
  • The Bankers Algorithm
  • Never allocate a request if it causes the current
    allocation state to become unsafe.

24
Safe State
  • A realizable state is safe if there is a sequence
    of processes, called a safe sequence, such that
  • The first process in the sequence can finish,
    because even if it requests all the resources it
    claims, there are enough free to satisfy its
    request.
  • The second process can finish if the first
    finishes.
  • The ith process can finish if some i - 1
    processes finish first. (for all i gt 1)

25
Realizable State
  • A state is realizable if the following conditions
    hold
  • No one claim is for more than the total resources
  • No process is holding more than its claim
  • Sum of held resources is not more than total
    resources.

26
Safe or Unsafe?

27

Safe or Unsafe?


28
Bankers Algorithm
If Allocation new request is greater than
what process originally claimed, abort
process else if allocation gt available then
suspend process until more resources are
available else - update available and
allocated in table If new table
is safe then grant request else deny
request and return table to original state and
suspend process
R1 R2 R3
29
Safe state algorithm
currentavail available possible true while
possible do find Pk where claimk -
allocationk lt currentavail (
find a process that could finish in this state)
if found then add the process allocation to
currentavail take process out of set
being searched. else possible false We are
in a safe state if all processes were removed
from the search set safe (rest null)
30
Deadlock detection
1. Mark each process that has all 0s in
allocation table 2. Initialize a temp vector W
equal to the available vector 3. Find a process
whose request is less than or equal to W 4. If
found, then add process allocation to W and mark
that process 5. If any processes remain unmarked,
then they are deadlocked
31
Dining Philosophers Problem
32
Homework Problems
  • Pages 281-284
  • Problems
  • 6.2
  • 6.8
  • 6.12
  • 6.13
Write a Comment
User Comments (0)
About PowerShow.com