You are on page 1of 3

Deadlock: Bridge Crossing Example

• Traffic only in one direction at a time.


• Each section of a bridge can be viewed as a resource.
Introduction to Deadlock • If a deadlock occurs, it can be resolved if one car backs
up (preempt resources and rollback).
• Several cars may have to be backed up if a deadlock
occurs.
Notice: The slides for this lecture have been largely based on those accompanying an earlier edition • Starvation is possible.
of the course text Operating Systems Concepts, 9th ed., by Silberschatz, Galvin, and Gagne. Many, if
not all, the illustrations contained in this presentation come from this source. Revised by X.M. based
on Professor Perrone’s notes.
CSCI 315 Operating Systems Design 1 CSCI 315 Operating Systems Design 2

Deadlock: Dining-Philosophers Example Traffic Deadlock


All philosophers start out hungry and
that they all pick up their left chopstick
at the same time.

When a philosopher manages to get a


chopstick, it is not released until a
second chopstick is acquired and the
philosopher
hil h has h eaten t his
hi share.
h

Question: Why did deadlock


happen? Enumerate all the conditions
that have to be satisfied for deadlock
to occur.

Question: What can be done to


guarantee that deadlock won’t
happen?
CSCI 315 Operating Systems Design 3 CSCI 315 Operating Systems Design 4

Concepts to discuss A System Model


• Resource types R1, R2, . . ., Rm
Deadlock CPU cycles, memory space, I/O devices
• Each resource type Ri has Wi instances.
Livelock • Each
E h process utilizes
tili a resource as
follows:
Spinlock vs. Blocking – request
– use
– release

CSCI 315 Operating Systems Design 5 CSCI 315 Operating Systems Design 6

1
Deadlock Characterization Resource Allocation Graph
Deadlock can arise if four conditions hold simultaneously:
Graph: G=(V,E)
• Mutual exclusion: only one process at a time can use a
resource.
• Hold and wait: a process holding at least one resource is • The nodes in V can be of two types (partitions):
waiting to acquire additional resources held by other
– P = {P1, P2, …, Pn}, the set consisting of all the
processes.
processes in the system.
p y
• No
N preemption:ti a resource can beb released
l d only
l voluntarily
l t il
by the process holding it, after that process has completed
its task. – R = {R1, R2, …, Rm}, the set consisting of all resource
• Circular wait: there exists a set {P0, P1, …, P0} of waiting types in the system.
processes such that P0 is waiting for a resource that is held • Request edge – directed edge P1  Rj
by P1, P1 is waiting for a resource that is held by
P2, …, Pn–1 is waiting for a resource that is held by • Assignment edge – directed edge Rj  Pi
Pn, and Pn is waiting for a resource that is held by P0.

CSCI 315 Operating Systems Design 7 CSCI 315 Operating Systems Design 8

Example of a Resource
Resource Allocation Graph
Allocation Graph
• Process

• Resource Type with 4 instances

• Pi requests instance of Rj
Pi
Rj

• Pi is holding an instance of Rj
Pi
Rj

CSCI 315 Operating Systems Design 9 CSCI 315 Operating Systems Design 10

Resource Allocation Graph With A Resource Allocation Graph With A Cycle


But No Deadlock
Deadlock

CSCI 315 Operating Systems Design 11 CSCI 315 Operating Systems Design 12

2
Resource Allocation Graph Resource Allocation Graph
Example 1 Example 2

CSCI 315 Operating Systems Design 13 CSCI 315 Operating Systems Design 14

Basic Facts
• If graph contains no cycles  no
deadlock.

• If graph contains a cycle 


– if only one instance per resource type, then
deadlock.
– if several instances per resource type,
possibility of deadlock.

CSCI 315 Operating Systems Design 15

You might also like