You are on page 1of 22

Deadlocks Definition

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

4/24/2012

CS241 2005 Roy Campbell, All Rights Reserved

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

Contents
Definitions Resources Conditions for deadlock Deadlock issues

4/24/2012

CS241 2005 Roy Campbell, All Rights Reserved

Definitions
A process is deadlocked if it is waiting for an event that will never occur Typically, but not necessarily, more than one process will be involved together in a deadlock (the deadly embrace)

4/24/2012

CS241 2005 Roy Campbell, All Rights Reserved

Example - Contention

Mechanism for Deadlock Control


4/24/2012 CS241 2005 Roy Campbell, All Rights Reserved 5

Synchronization Deadlock
1 2 3 4 5
2 3 4 5
4/24/2012

Process P(); { A.P(); B.P(); B.V(); A.V(); }

0 6

Process Q(); { A.P(); B.P(); B.V(); A.V(); }

External Semaphore A(1), B(1); External Semaphore A(0), B(1); External Semaphore A(0), B(0); External Semaphore A(0), B(1); External Semaphore A(1), B(1);
CS241 2005 Roy Campbell, All Rights Reserved 6

Synchronization Deadlock
1 2 Process P(); { A.P(); B.P(); B.V(); A.V(); } 1 3
Process Q(); { B.P(); A.P(); A.V(); B.V(); }

1 External Semaphore A(1), B(1); 2 External Semaphore A(0), B(1); 3 External Semaphore A(0), B(0);
4/24/2012 CS241 2005 Roy Campbell, All Rights Reserved 7

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

Resources
A resource is a commodity needed by a process Habermann: ``resources work by order of a process or another resource; processes do not

4/24/2012

CS241 2005 Roy Campbell, All Rights Reserved

Resources
Resources can be either: Serially reusable: e.g., CPU, memory, disk space, I/O devices, files
Acquire use release

4/24/2012

CS241 2005 Roy Campbell, All Rights Reserved

10

Resources
Or: Consumable: produced by a process, needed by a process; e.g., Messages, buffers of information, interrupts
Create acquire use (resource ceases to exist after it has been used, so it is not released. )

4/24/2012

CS241 2005 Roy Campbell, All Rights Reserved

11

Resources
Resources can also be either: Pre-emptible: e.g., CPU, central memory Non-pre-emptible: e.g., Tape drives

4/24/2012

CS241 2005 Roy Campbell, All Rights Reserved

12

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

Conditions for Deadlock


The following four conditions are both necessary and sufficient for deadlock: 1. Mutual exclusion 2. Hold and wait condition 3. No preemption condition 4. Circular wait condition

4/24/2012

CS241 2005 Roy Campbell, All Rights Reserved

14

Mutual Exclusion
Processes claim exclusive control of the resources they require

4/24/2012

CS241 2005 Roy Campbell, All Rights Reserved

15

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

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

17

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

18

Its difficult to take a tape drive away from a process that is busy writing a tape

4/24/2012

CS241 2005 Roy Campbell, All Rights Reserved

19

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

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

21

Summary
Definitions Resources Conditions for deadlock Deadlock issues

4/24/2012

CS241 2005 Roy Campbell, All Rights Reserved

22

You might also like