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

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

Deadlocks
Image of page 1

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

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!
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) }
Image of page 3

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

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”
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
Image of page 5

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

Real World Deadlocks? Truck A has to wait for truck B to move Not deadlocked
Image of page 6
Real World Deadlocks? Gridlock
Image of page 7

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

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!
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
Image of page 9

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

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!
Image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern