deadlock-07 - Deadlocks System Model There are non-shared...

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

View Full Document Right Arrow Icon
Deadlocks
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
For example: Semaphores semaphore: mutex1 = 1 /* protects resource 1 */ mutex2 = 1 /* protects resource 2 */ Process A code: { /* initial compute */ P(mutex1) P(mutex2) /* use both resources */ V(mutex2) V(mutex1) } Process B code: { /* initial compute */ P(mutex2) P(mutex1) /* use both resources */ V(mutex2) V(mutex1) }
Background image of page 3

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

View Full DocumentRight Arrow Icon
Deadlocks Definition: 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 Event is the acquire of 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 4
Four Conditions for Deadlock Coffman et. al. 1971 Necessary conditions for deadlock to exist: Mutual Exclusion At least one resource must be held is 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 {P 1 , P 2 , … P N }, such that P 1 is waiting for P 2 , P 2 for P 3 , …. and P N for P 1 All four conditions must hold for deadlock to occur
Background image of page 5

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

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

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

View Full DocumentRight Arrow Icon
Avoiding deadlock How do cars do it? Never block an intersection Must back up if you find yourself doing so Why does this work? “Breaks” a wait-for relationship Illustrates a sense in which intransigent waiting (refusing to release a resource) is one key element of true deadlock!
Background image of page 8
Testing for deadlock Steps Collect “process state” and use it to build a graph Ask each process “are you waiting for anything”? Put an edge in the graph if so We need to do this in a single instant of time, not while things might be changing Now need a way to test for cycles in our graph
Background image of page 9

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

View Full DocumentRight Arrow Icon
Testing for deadlock One way to find cycles Look for a node with no outgoing edges Erase this node, and also erase any edges coming into it Idea: This was a process people might have been waiting for, but it wasn’t waiting for anything else If (and only if) the graph has no cycles, we’ll eventually be able to erase the whole graph!
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 57

deadlock-07 - Deadlocks System Model There are non-shared...

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

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