Deadlocks Definition

CS 241 Lecture 15
T: Ch 3, pp 159-183
Roy Campbell

4/24/2012

CS241 © 2005 Roy Campbell, All Rights Reserved

1

Discussion
 Operating systems acquire dedicated access to shared resources
 How can conflicts arise?  How can you prevent conflicts?

4/24/2012

CS241 © 2005 Roy Campbell, All Rights Reserved

2

Contents Definitions Resources Conditions for deadlock Deadlock issues 4/24/2012 CS241 © 2005 Roy Campbell. All Rights Reserved 3 .

Definitions A process is deadlocked if it is waiting for an event that will never occur Typically. but not necessarily. All Rights Reserved 4 . more than one process will be involved together in a deadlock (the deadly embrace) 4/24/2012 CS241 © 2005 Roy Campbell.

All Rights Reserved 5 .Contention Mechanism for Deadlock Control 4/24/2012 CS241 © 2005 Roy Campbell.Example .

V().V(). A.Synchronization Deadlock 1 2 3 4 5 2 3 4 5 4/24/2012 Process P().V(). B(1). B. B(1). CS241 © 2005 Roy Campbell. B. B(1). } 0 6 Process Q().V(). } External Semaphore A(1). B(0).P(). A. External Semaphore A(0).P(). External Semaphore A(1). { A.P(). All Rights Reserved 6 . B. B. B(1).P(). External Semaphore A(0). { A. External Semaphore A(0).

{ A. } 1 External Semaphore A(1). 2 External Semaphore A(0). B. A. A.V(). B(1). All Rights Reserved 7 . 4/24/2012 CS241 © 2005 Roy Campbell. B.P(). } 1 3 Process Q(). B. B(1). 3 External Semaphore A(0).V(). B(0).P().P(). { B.V().V(). A.P().Synchronization Deadlock 1 2 Process P().

Definitions A process is indefinitely postponed if it is delayed repeatedly over a long period of time while the attention of the system is given to other processes i.e.. Logically the process may proceed but the system never gives it the CPU 4/24/2012 CS241 © 2005 Roy Campbell. All Rights Reserved 8 .

processes do not’’ 4/24/2012 CS241 © 2005 Roy Campbell.Resources A resource is a commodity needed by a process Habermann: ``resources work by order of a process or another resource. All Rights Reserved 9 .

disk space. files Acquire use release 4/24/2012 CS241 © 2005 Roy Campbell. I/O devices.. CPU. memory. All Rights Reserved 10 .Resources Resources can be either:  Serially reusable: e.g.

Messages.Resources Or:  Consumable: produced by a process. buffers of information. All Rights Reserved 11 . needed by a process.g. interrupts Create acquire use (resource ceases to exist after it has been used. ) 4/24/2012 CS241 © 2005 Roy Campbell. so it is not released. e..

All Rights Reserved 12 ..g..Resources Resources can also be either:  Pre-emptible: e. central memory  Non-pre-emptible: e.g. CPU. Tape drives 4/24/2012 CS241 © 2005 Roy Campbell.

Resources Or resources can be:  Shared among several processes  Dedicated exclusively to a single process 4/24/2012 CS241 © 2005 Roy Campbell. All Rights Reserved 13 .

No preemption condition 4. Circular wait condition 4/24/2012 CS241 © 2005 Roy Campbell. All Rights Reserved 14 .Conditions for Deadlock The following four conditions are both necessary and sufficient for deadlock: 1. Hold and wait condition 3. Mutual exclusion 2.

All Rights Reserved 15 .Mutual Exclusion  Processes claim exclusive control of the resources they require 4/24/2012 CS241 © 2005 Roy Campbell.

Wait-for Condition Processes hold resources already allocated to them while waiting for additional resources 4/24/2012 CS241 © 2005 Roy Campbell. All Rights Reserved 16 .

All Rights Reserved 17 .Process 1 P(s1) P(s2) Work V(s2) V(s1) Blocked Process 2 P(s2) P(s3) Work V(s3) V(s2) Process 3 P(s3) P(s1) Work V(s1) V(s3) 4/24/2012 CS241 © 2005 Roy Campbell.

All Rights Reserved 18 .No Preemption Condition Resources cannot be removed from the processes holding them until used to completion 4/24/2012 CS241 © 2005 Roy Campbell.

All Rights Reserved 19 .Its difficult to take a tape drive away from a process that is busy writing a tape 4/24/2012 CS241 © 2005 Roy Campbell.

Circular Wait Condition  A circular chain of processes exists in which each process holds one or more resources that are requested by the next process in the chain 4/24/2012 CS241 © 2005 Roy Campbell. All Rights Reserved 20 .

All Rights Reserved 21 .Process 1 P(s1) P(s2) Work V(s2) V(s1) Blocked Process 2 P(s2) P(s3) Work V(s3) V(s2) Process 3 P(s3) P(s1) Work V(s1) V(s3) 4/24/2012 CS241 © 2005 Roy Campbell.

Summary Definitions Resources Conditions for deadlock Deadlock issues 4/24/2012 CS241 © 2005 Roy Campbell. All Rights Reserved 22 .

Sign up to vote on this title
UsefulNot useful