Docsity

Deadlock - Operating System Design and Implementation - Lecture Slides, Slides of Operating Systems

Partial preview of the text

Download Deadlock - Operating System Design and Implementation - Lecture Slides and more Slides Operating Systems in PDF only on Docsity!

(^1) 15-410, F'

Deadlock (1)

Dave Eckhardt

Todd Mowry

Roger Dannenberg

Garth Gibson

Bruce Maggs

Geoff Langdale

L13_Deadlock

Synchronization

l Today's goals (to be on track with P2)

  • Coded mutexes and condition variables
  • Thoughtful design for thr_create(), maybe thr_join()
  • Some code for thr_create(), and some “experience”
  • The startle test running
  • Passing some mutex/cvar tests

l Next steps...

  • Debugging cyclone / agility_drill
  • Ok if some components are “demo quality” to start out with...

Synchronization – Readings

l Next three lectures

  • OSC – Deadlock: 6.5.3, 6.6.3, Chapter 7
  • OS:P+P – Advanced Synchronization: Chapter 6

l Reading ahead

  • Virtual Memory (continued)
  • Scheduling

l Don't forget about reading list on web site

Outline

l Process resource graph

l What is deadlock?

l Deadlock prevention

l Next time

  • Deadlock avoidance
  • Deadlock recovery

Process/Resource graph

Tape 1

P

Tape 2

P

Tape 3

P

Request

Process/Resource graph

Tape 1

P

Tape 2

P

Tape 3

P

Allocation

Definition of Deadlock

l A deadlock

  • Set of N processes
  • Each waiting for an event l ...which can be caused only by another process in the set

l Every process will wait forever

Deadlock Examples

l Simplest form

  • Process 1 owns printer, wants tape drive
  • Process 2 owns tape drive, wants printer

l Less-obvious

  • Three tape drives
  • Three processes l Each has one tape drive l Each wants “just” one more
  • Can't blame anybody, but problem is still there

Mutual Exclusion

l Resources aren't “thread-safe” (“reentrant”)

l Must be allocated to one process/thread at a time

l Can't be shared

  • Programmable Interrupt Timer l Can't have a different reload value for each process

Hold & Wait

l Process holds some resources while waiting for more

mutex_lock(&m1);

mutex_lock(&m2);

mutex_lock(&m3);

l This locking behavior is typical

Circular Wait

l Process 0 needs something process 4 has

  • Process 4 needs something process 7 has
  • Process 7 needs something process 1 has
  • Process 1 needs something process 0 has – uh-oh...

l Described as “cycle in the resource graph”

Cycle in Resource Graph

  • Tape
    • P
      • Tape
        • P
          • Tape
            • P
  • Tape Release
    • P
      • Tape
        • P
          • Tape
            • P
  • Tape Reallocation
    • P
      • Tape
        • P
          • Tape
            • P
      • Tape
    • P
  • Tape - P - Tape - P