deadlocks(jntumaterials.com)

Upload: sri-harsha

Post on 07-Aug-2018

230 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/20/2019 Deadlocks(jntumaterials.com)

    1/29

     

    Deadlock Prevention, Avoidance,

    and Detection

  • 8/20/2019 Deadlocks(jntumaterials.com)

    2/29

     

    The Deadlock problem  In a computer system deadlocks arise when

    members of a group of processes which

    hold resources are blocked indefinitely

    from access to resources held by other

     processes within the group.

  • 8/20/2019 Deadlocks(jntumaterials.com)

    3/29

     

    Deadlock example Pi requests one I! controller and the

    system allocates one.

    P " requests one I! controller and again the

    system allocates one.

    Pi wants another I! controller but has to

    wait since the system ran out of I!controllers.

    P " wants another I! controller and waits.

  • 8/20/2019 Deadlocks(jntumaterials.com)

    4/29

     

    Conditions for deadlocks  Mutual exclusion. #o resource can be shared by

    more than one process at a time.

     Hold and wait . $here must exist a process that isholding at least one resource and is waiting toacquire additional resources that are currently

     being held by other processes.

     No preemption. A resource cannot be preempted. Circular wait . $here is a cycle in the wait%for

    graph.

  • 8/20/2019 Deadlocks(jntumaterials.com)

    5/29

     

    An example

    &ity A &ity ' bridge

    &ity A &ity '

    river  river 

     bridge

  • 8/20/2019 Deadlocks(jntumaterials.com)

    6/29

     

    Graph-theoretic models  (ait%for graph.

    )esource%allocation graph.

  • 8/20/2019 Deadlocks(jntumaterials.com)

    7/29 

    (ait%for graph

    P*

    P+P

    P-

    P

  • 8/20/2019 Deadlocks(jntumaterials.com)

    8/29 

    )esource allocation graph

    P* P-

    P

    r* r-

    )esource allocation graph

    (ithout deadlock 

    P* P-

    P

    (ith deadlock 

  • 8/20/2019 Deadlocks(jntumaterials.com)

    9/29

  • 8/20/2019 Deadlocks(jntumaterials.com)

    10/29 

    Strategies for handling

    deadlocks Deadlock prevention. Prevents deadlocks by

    restraining requests made to ensure that at least

    one of the four deadlock conditions cannot occur. Deadlock avoidance. Dynamically grants a

    resource to a process if the resulting state is safe. Astate is safe if there is at least one execution

    sequence that allows all processes to run tocompletion.

    Deadlock detection and recovery. Allowsdeadlocks to form/ then finds and breaks them.

  • 8/20/2019 Deadlocks(jntumaterials.com)

    11/29 

    $wo types of deadlocks )esource deadlock0 uses A#D condition.

    A#D condition0 a process that requires resources

    for execution can proceed when it has acquiredall those resources.

    &ommunication deadlock0 uses !) condition.

      !) condition0 a process that requires resourcesfor execution can proceed when it has acquired at

    least one of those resources.

  • 8/20/2019 Deadlocks(jntumaterials.com)

    12/29 

    P%out%of 12 condition which means that a

     process simultaneously requests 2

    resources and remains blocked until it is

    granted any P of those resources.

    A#D%!) model, which may specify any

    combination of A#D and !) models.

    3.g. a A#D 4b !) c5.

  • 8/20/2019 Deadlocks(jntumaterials.com)

    13/29 

    Deadlock conditions  $he condition for deadlock in a system using the

    A#D condition is the existence of a cycle.

    $he condition for deadlock in a system using the!) condition is the existence of a knot .

    A knot 465 consists of a set of nodes such that forevery node a in 6, all nodes in 6 and only the

    nodes in 6 are reachable from node a.

  • 8/20/2019 Deadlocks(jntumaterials.com)

    14/29 

    3xample0 !) condition

    P* P-

    P

    P+

    P

    P* P-

    P

    P+

    P

     #o deadlock  Deadlock 

  • 8/20/2019 Deadlocks(jntumaterials.com)

    15/29 

    Deadlock Prevention  *. A process acquires all the needed resources

    simultaneously before it begins its execution,

    therefore breaking the hold and wait condition. 3.g. In the dining philosophers7 problem, each

     philosopher is required to pick up both forks at

    the same time. If he fails, he has to release the

    fork4s5 4if any5 he has acquired.

    Drawback0 over%cautious.

  • 8/20/2019 Deadlocks(jntumaterials.com)

    16/29 

    -. All resources are assigned unique numbers. A process

    may request a resource with a unique number I only if it

    is not holding a resource with a number less than or equalto I and therefore breaking the circular wait condition.

    3.g. In the dining philosophers problem, each philosopher

    is required to pick a fork that has a larger id than the one

    he currently holds. $hat is, philosopher P needs to pick

    up fork 8 and then 8*/ the other philosopher Pi should

     pick up fork 8i followed by 8i%*.

    Drawback0 over%cautions. 

  • 8/20/2019 Deadlocks(jntumaterials.com)

    17/29 

    . 3ach process is assigned a unique priority number. $he priority numbers decide whether process Pi should wait for process P" and therefore break the non%preemption condition.

    3.g. Assume that the philosophers7 priorities are based ontheir ids, i.e., Pi has a higher priority than P" if i 9". In thiscase Pi is allowed to wait for Pi:* for I;*,-,,+. P is notallowed to wait for P*. If this case happens, P has to abort

     by releasing its acquired fork4s5 4if any5.

    Drawback0 starvation. $he lower priority one may always berolled back.

  • 8/20/2019 Deadlocks(jntumaterials.com)

    18/29 

    +. Practically it is impossible to provide a

    method to break the mutual exclusion

    condition since most resources are

    intrinsically non%sharable, e.g., two

     philosophers cannot use the same fork at

    the same time.

  • 8/20/2019 Deadlocks(jntumaterials.com)

    19/29 

    A Deadlock Prevention 3xampleWait-die

    (ants )esource >old )esource

    !ld process %%%%%  ?oung process

    *@ -@

    (aits

  • 8/20/2019 Deadlocks(jntumaterials.com)

    20/29 

    (ants resource >olds resource

    ?oung process -@ !ld process *@

    Dies

    (ait%die is a non%preemptive method.

  • 8/20/2019 Deadlocks(jntumaterials.com)

    21/29

     

    Wound-wait 

    (ants resource >old resource

     

    !ld process *@ ?oung process -@

    Preempts

  • 8/20/2019 Deadlocks(jntumaterials.com)

    22/29

     

    (ants resource >old resource

    ?oung process -@ !ld process *@

     

    (aits

  • 8/20/2019 Deadlocks(jntumaterials.com)

    23/29

     

    An exampleProcess id priority *st request

    timelength )etry

    interval

    P* - * * *

    P- * *. - *

    P + -.* - -

    P+ . * *

    P +.@ -

  • 8/20/2019 Deadlocks(jntumaterials.com)

    24/29

     

    Deadlock Avoidance 8our resources A'&D. A has instances, ' has instances, &

    >as + instances and D has - instances.

    Process Allocation Bax

      A'&D A'&D

    P* @** +***

    P- @*@@ @-*-

    P ***@ +-*@

    P+ **@* **@*

    P @@@@ -**@

    Is the current state safeC

    If P requests for 4*,@,*,@5, can this be grantedC

  • 8/20/2019 Deadlocks(jntumaterials.com)

    25/29

     

    Deadlock Detection and

    )ecovery &entrali=ed approaches

    Distributed approaches

    >ierarchical approaches

  • 8/20/2019 Deadlocks(jntumaterials.com)

    26/29

     

    &entrali=ed approachesBachine @ Bachine * &oordinator  &oordinator 

    A <

    '

    >olds

    (ants

    >olds

    &

    $

    <(ants

    >olds

    &

    $

  • 8/20/2019 Deadlocks(jntumaterials.com)

    27/29

     

    Distributed approaches A copy of the global wait%for graph is kept

    at each site with the result that each site has

    a global view of the system.

    $he global wait%for graph is divided and

    distributed to different sites.

  • 8/20/2019 Deadlocks(jntumaterials.com)

    28/29

     

    &handy%Bisra%>aas distributed

    deadlock detection algorithm

    @ * -

    +

    E

    Bachine @ Bachine * Bachine -

    4@,E,@5

    4@,-,5

    4@,+,5

    4@,,5

  • 8/20/2019 Deadlocks(jntumaterials.com)

    29/29

    >ierarchical approaches In hierarchical deadlock detection algorithms, sites are arranged hierarchically

    in a tree. A site detects deadlocks involving only its descendant sites.

    8or example, let A, ' and & be controllers such that & is the lowest commonancestor of A and '.