Deadlocks: Detection & Avoidance
(Chapter 32)
CS 4410 Operating Systems
The slides are the product of many rounds of teaching CS 4410 by Professors Agarwal, Bracy, George, Sirer, and Van Renesse.
Deadlocks: Detection & Avoidance (Chapter 32) CS 4410 - - PowerPoint PPT Presentation
Deadlocks: Detection & Avoidance (Chapter 32) CS 4410 Operating Systems The slides are the product of many rounds of teaching CS 4410 by Professors Agarwal, Bracy, George, Sirer, and Van Renesse. System Model Exclusive (one-at-a-time)
The slides are the product of many rounds of teaching CS 4410 by Professors Agarwal, Bracy, George, Sirer, and Van Renesse.
2
3
4
file_mutex = 1 /* protects file resource */ printer_mutex = 1 /* protects printer resource */
{ /* initial compute */ P(file_mutex) P(printer_mutex) /* use resources */ V(printer_mutex) V(file_mutex) } { /* initial compute */ P(printer_mutex) P(file_mutex) /* use resources */ V(file_mutex) V(printer_mutex) }
5
class Philosopher: chopsticks[N] = [Semaphore(1),…] def __init__(mynum) self.id = mynum def eat(): right = self.id left = (self.id+1) % N while True: P(chopsticks[left]) P(chopsticks[right]) # om nom nom V(chopsticks[right]) V(chopsticks[left])
6
≥ 1 resource must be held in non-sharable mode
∃ a process holding 1 resource & waiting for another
Resources cannot be preempted
∃ a set of processes {P1, P2, … PN}, such that P1 is waiting for P2, P2 for P3, …. and PN for P1
7
8
9
10
11
12
13
14
Find node w/o outgoing edges Erase node Erase edges coming into it
15
16
17
18
19
20
21
Module:: foo() { lock.acquire(); doSomeStuff();
doOtherStuff(); lock.release(); } Module:: foo() { doSomeStuff();
doOtherStuff(); }
22
23
1 2 3 4 1 2 1
24
class Philosopher: chopsticks[N] = [Semaphore(1),…] def __init__(mynum) self.id = mynum def eat(): right = self.id % N left = (self.id + 1) % N while True: P(left) P(right) # om nom nom V(right) V(left)
25
26
27
28
29
Current state is safe because a safe sequence exists: [p1, p0, p2]
What if p2 requests 1 drive? Grant or not?
30
31
32
33
34
35