06-deadlocks - Deadlocks DetectionandAvoidance Prof.Sirer...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
Deadlocks Detection and Avoidance Prof. Sirer CS 4410 Cornell University
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
System Model There are non-shared computer resources Maybe more than one instance Printers, Semaphores, Tape drives, CPU Processes need access to these resources Acquire resource If resource is available, access is granted If not available, the process is blocked Use resource Release resource Undesirable scenario: Process A acquires resource 1, and is waiting for resource 2 Process B acquires resource 2, and is waiting for resource 1   Deadlock!
Background image of page 2
Example 1: Semaphores semaphore: mutex1 = 1 /* protects resource 1 */ mutex2 = 1 /* protects resource 2 */ Process A code: { /* initial compute */ P(file) P(printer) /* use both resources */ V(printer) V(file) } Process B code: { /* initial compute */ P(printer) P(file) /* use both resources */ V(file) V(printer) }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Simplest deadlock
Background image of page 4
Example 2: Dining  Philosophers Philosophers go out for Chinese food They need exclusive access to two chopsticks to  eat their food class Philosopher: chopsticks[N] = [Semaphore(1),…] Def __init__(mynum) self.id = mynum Def eat(): right = (self.id+1) % N left = (self.id-1+N) % N while True: # om nom nom
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example 2: Dining  Philosophers Philosophers go out for Chinese food They need exclusive access to two chopsticks to  eat their food class Philosopher: chopsticks[N] = [Semaphore(1),…] Def __init__(mynum) self.id = mynum Def eat(): right = (self.id+1) % N left = (self.id-1+N) % N while True: P(left) P(right) # om nom nom V(right) V(left)
Background image of page 6
More Complicated Deadlock
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Deadlocks Deadlock exists among a set of processes if  Every process is waiting for an event  This event can be caused only by another process in the set that in  turn is waiting for an event Typically, the event is the acquire or release of another resource Kansas 20th century law: “When two trains approach each other at a  crossing, both shall come to a full stop and neither shall start up again until  the other has gone”
Background image of page 8
Four Conditions for Deadlock Necessary conditions for deadlock to exist: Mutual Exclusion At least one resource must be held in non-sharable mode Hold and wait There exists a process holding a resource, and waiting for another No preemption Resources cannot be preempted Circular wait There exists a set of processes {P1, P2, … PN}, such that P1 is waiting for P2, P2 for P3, …. and PN for P1 All  four conditions must hold for deadlock to occur
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Truck A has to wait for truck B to move Not deadlocked Real World Deadlocks?
Background image of page 10
Gridlock
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/07/2011 for the course CS 4410 taught by Professor Vollset during the Spring '07 term at Cornell University (Engineering School).

Page1 / 62

06-deadlocks - Deadlocks DetectionandAvoidance Prof.Sirer...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online