SlideShare ist ein Scribd-Unternehmen logo
1 von 79
Operating Systems Principles Process Management and Coordination Lecture 6: Deadlocks 主講人:虞台文
Content ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Operating Systems Principles Process Management and Coordination   Lecture 6: Deadlocks Deadlocks with Reusable and Consumable Resources
Deadlocks
Deadlocks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reusable/Consumable Resources ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reusable/Consumable Resources ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Main topic of the lecture Reusable  Resources
Example (File Sharing) p1: ... open(f1,w);  open(f2,w); ... p2: ... open(f2,w);  open(f1,w); ... Deadlock when executed concurrently
Example (Message Passing) p1: ... if( C )send(p2,m); while(1){ recv(p3,m);  ... send(p2,m);  } Deadlock when  C  is  not  true p2: ... while(1){ recv(p1,m);  ... send(p3,m);  } p3: ... while(1){ recv(p2,m);  ... send(p1,m);  } Assume that  send / recv  are  blocking  operations.
Deadlock, Livelock, and Starvation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Deadlock  and  livelock  will lead to  starvation . But, the  inverse  is  not  necessary  true .
Examples: Starvation Not Due to Deadlock or Livelock ,[object Object],[object Object],[object Object],[object Object],[object Object],Deadlock  and  livelock  will lead to  starvation . But, the  inverse  is  not  necessary  true .
Operating Systems Principles Process Management and Coordination   Lecture 6: Deadlocks Approaches to the Deadlock Problem
Approaches to Deadlock Problem ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Operating Systems Principles Process Management and Coordination   Lecture 6: Deadlocks System Model
Resource Graph ,[object Object],[object Object],[object Object],[object Object]
State Transitions by  p 1  Process  S 0 S 1 S 2 S 3 The state transition diagram described below is  not   complete . The actual number of states  depends  on  possible operations  of processes. R p 1 p 2 R p 1 p 2 R p 1 p 2 R p 1 p 2 Request  R (by   p 1 ) Acquire  R (by   p 1 ) Release  R (by   p 1 )
Process Operations on Resources ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Deadlock States and Safe States ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example p 1  and  p 2  both need  R 1  and  R 2 . R 1 R 2 p 1 p 2 p1: Request( R1 );  Request( R2 ); Release( R2 ); Release( R1 );  p2: Request( R2 );  Request( R1 ); Release( R1 ); Release( R2 );
Example p1: Request( R1 );  Request( R2 ); Release( R2 ); Release( R1 );  p2: Request( R2 );  Request( R1 ); Release( R1 ); Release( R2 );
Example p1: Request( R1 );  Request( R2 ); Release( R2 ); Release( R1 );  p2: Request( R2 );  Request( R1 ); Release( R1 ); Release( R2 );
Example p1: Request( R1 );  Request( R2 ); Release( R2 ); Release( R1 );  p2: Request( R2 );  Request( R1 ); Release( R1 ); Release( R2 );
Example p1: Request( R1 );  Request( R2 ); Release( R2 ); Release( R1 );  p2: Request( R2 );  Request( R1 ); Release( R1 ); Release( R2 );
Example R 1 R 2 p 1 p 2
Example p 1   is blocked. p 2   is blocked.
Example A deadlock state. No  state is  safe  since the deadlock state is always  reachable .
Necessary Condition for Deadlock A  cycle  in the  resource graph  is a necessary condition for deadlock.
Operating Systems Principles Process Management and Coordination   Lecture 6: Deadlocks Deadlock Detection
Graph Reduction Technique ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Graph Reduction Technique ,[object Object],[object Object],[object Object],[object Object],p 1 p 2 p 4 p 5 p 3 R 1 R 2 R 3
Graph Reduction Technique ,[object Object],[object Object],[object Object],[object Object],p 1 p 2 p 4 p 5 p 3 R 1 R 2 R 3
Graph Reduction Technique ,[object Object],[object Object],[object Object],[object Object],p 1 p 2 p 4 p 5 p 3 R 1 R 2 R 3
Graph Reduction Technique ,[object Object],[object Object],[object Object],[object Object],p 1 p 2 p 4 p 5 p 3 irreducible Deadlock detected R 1 R 2 R 3
Graph Reduction Technique ,[object Object],[object Object],[object Object],[object Object]
Special Cases of Deadlock Detection ,[object Object],[object Object],[object Object],[object Object]
Testing for specific process  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Continuous Deadlock Detection ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Immediate Allocations ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Granted immediately Non-Expedient State Expedient State Satisfiable p 1 p 2 p 4 p 5 p 3 R 1 R 2 R 3 p 1 p 2 p 4 p 5 p 3 R 1 R 2 R 3
Immediate Allocations ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Sufficient condition for deadlock.
Sufficient Condition for Deadlock ,[object Object],[object Object],[object Object],[object Object],Expedient State p 1 p 2 p 4 p 5 p 3 R 1 R 2 R 3
Sufficient Condition for Deadlock ,[object Object],[object Object],[object Object],[object Object],Expedient State Knot p 1 p 2 p 4 p 5 p 3 R 1 R 2 R 3
Sufficient Condition for Deadlock ,[object Object],[object Object],[object Object],[object Object],Expedient State p 1 p 2 p 4 p 5 p 3 R 1 R 2 R 3
Sufficient Condition for Deadlock ,[object Object],[object Object],[object Object],[object Object],Expedient State Knot p 1 p 2 p 4 p 5 p 3 R 1 R 2 R 3
Knot is  Not  Necessary for Deadlock ,[object Object],[object Object],[object Object],[object Object],Expedient State Deadlock on a condition  w/o  a knot. p 1 p 2 p 4 p 5 p 3 R 1 R 2 R 3
Single-Unit Resources ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Deadlocked Not  Deadlocked p 1 p 2 R 1 R 2 p 1 p 2 R 1 R 2
Single-Unit Resources ,[object Object],[object Object],[object Object],[object Object],[object Object]
Deadlock Detection in Distributed Systems ,[object Object],[object Object]
Central Coordinator Approach ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],p 2 p 1 M 1 p 3 p 4 M 2
Phantom Deadlocks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object], Due to  timeout ,  p 3   cancel  the request. But, the message passed to CC is  delayed p 1   requesting the resource holding by   p 4   causes   phantom  deadlock. phantom edge Deadlock p 2 p 1 M 1 p 3 p 4 M 2 p 2 p 1 M 1 p 3 p 4 M 2
Distributed Approach ,[object Object],[object Object],[object Object],[object Object],p 1    p 2 p 1     p 2     p 3 p 1     p 2     p 3     p 4 p 1     p 2     p 3     p 7 p 1     p 2     p 3     p 4     p 5 p 1     p 2     p 3     p 4     p 5     p 1 p 1     p 2     p 3     p 4     p 5     p 6 p 1     p 2     p 3     p 4      p 5     p 6    p 4 p 1 p 2 p 3 p 7 p 6 p 4 p 5 M 1 M 2 M 3 M 4
Distributed Approach ,[object Object],[object Object],[object Object],[object Object],p 1    p 2 p 1     p 2     p 3 p 1     p 2     p 3     p 4 p 1     p 2     p 3     p 7 p 1     p 2     p 3     p 4     p 5 p 1     p 2     p 3     p 4     p 5     p 1 p 1     p 2     p 3     p 4     p 5     p 6 p 1     p 2     p 3     p 4      p 5     p 6    p 4 Deadlock detected by  M 4 . Deadlock detected by  M 1 . p 1 p 2 p 3 p 7 p 6 p 4 p 5 M 1 M 2 M 3 M 4
Operating Systems Principles Process Management and Coordination   Lecture 6: Deadlocks Recovery from Deadlock
Recovery from Deadlock ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Operating Systems Principles Process Management and Coordination   Lecture 6: Deadlocks Dynamic Deadlock Avoidance
Deadlock Avoidance ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Prior Knowledge for Deadlock Avoidance ,[object Object],[object Object],[object Object]
Maximum Claim Graph (MCG) ,[object Object],[object Object],[object Object],p 1 p 2 R
State Transition Using MCG ,[object Object],[object Object],[object Object],S 0 p 1 R p 2 S 1 Request  R (by   p 2 ) S 2 Acquire  R (by   p 2 ) S 3 Request  R (by   p 1 ) p 1 R p 2 p 1 R p 2 p 1 R p 2 S 4 Acquire  R (by   p 1 ) p 1 R p 2
The Banker’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Testing for safety algorithm (Dijkstra 1968)
The Banker’s Algorithm p 1 p 2 p 3 R 1 R 2
The Banker’s Algorithm Which of the requests can  safely  be  granted ? Can  p 1  R 1   be  safely  be  granted ? Can  p 2  R 1   be  safely  be  granted ? Can  p 3  R 1   be  safely  be  granted ? R 1 R 2 p 1 p 2 p 3
The Banker’s Algorithm Can  p 1  R 1   be  safely  be  granted ? Can  p 2  R 1   be  safely  be  granted ? Can  p 3  R 1   be  safely  be  granted ? Temporarily grant Can such an RAG be  completely reducible? R 1 R 2 p 1 p 2 p 3
The Banker’s Algorithm Can  p 1  R 1   be  safely  be  granted ? Can  p 2  R 1   be  safely  be  granted ? Can  p 3  R 1   be  safely  be  granted ? p 1 p 2 p 3 Temporarily grant Can such an RAG be  completely reducible?  R 1 R 2
The Banker’s Algorithm Can  p 1  R 1   be  safely  be  granted ? Can  p 2  R 1   be  safely  be  granted ? Can  p 3  R 1   be  safely  be  granted ? granted Can such an RAG be  completely reducible?  R 1 R 2 p 1 p 2 p 3
The Banker’s Algorithm Can  p 1  R 1   be  safely  be  granted ? Can  p 2  R 1   be  safely  be  granted ? Can  p 3  R 1   be  safely  be  granted ?  R 1 R 2 p 1 p 2 p 3
The Banker’s Algorithm Can  p 1  R 1   be  safely  be  granted ? Can  p 2  R 1   be  safely  be  granted ? Can  p 3  R 1   be  safely  be  granted ? Can such an RAG be  completely reducible? Temporarily grant   R 1 R 2 p 1 p 2 p 3
The Banker’s Algorithm Can  p 1  R 1   be  safely  be  granted ? Can  p 2  R 1   be  safely  be  granted ? Can  p 3  R 1   be  safely  be  granted ?   not granted R 1 R 2 p 1 p 2 p 3
The Banker’s Algorithm Can  p 1  R 1   be  safely  be  granted ? Can  p 2  R 1   be  safely  be  granted ? Can  p 3  R 1   be  safely  be  granted ?   R 1 R 2 p 1 p 2 p 3
The Banker’s Algorithm Can  p 1  R 1   be  safely  be  granted ? Can  p 2  R 1   be  safely  be  granted ? Can  p 3  R 1   be  safely  be  granted ?   Can such an RAG be  completely reducible? Temporarily grant R 1 R 2 p 1 p 2 p 3
The Banker’s Algorithm Can  p 1  R 1   be  safely  be  granted ? Can  p 2  R 1   be  safely  be  granted ? Can  p 3  R 1   be  safely  be  granted ?   p 1 p 2 p 3 Can such an RAG be  completely reducible? Temporarily grant  R 1 R 2
The Banker’s Algorithm Can  p 1  R 1   be  safely  be  granted ? Can  p 2  R 1   be  safely  be  granted ? Can  p 3  R 1   be  safely  be  granted ?    granted p 1 p 2 p 3 R 1 R 2
Special Case: Single-Unit Resource ,[object Object],[object Object],[object Object],[object Object]
Operating Systems Principles Process Management and Coordination   Lecture 6: Deadlocks Deadlock Prevention
Deadlock Prevention ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Conditions for a Deadlock ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Eliminating   any  of these conditions would  make deadlock impossible .
Deadlock Prevention ,[object Object],[object Object],[object Object],[object Object],Eliminating  any  of ,[object Object],[object Object],[object Object],[object Object],[object Object]
Deadlock Prevention ,[object Object],[object Object],[object Object],[object Object],Eliminating  any  of ,[object Object],[object Object],[object Object],[object Object],[object Object]
Deadlock Prevention ,[object Object],[object Object],[object Object],[object Object],Eliminating  any  of ,[object Object],[object Object],Fact : A  cycle  in the resource graph can develop only when processes  request  the same resources in the  different   order .
Comparisons

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock Detection in Distributed Systems
Deadlock Detection in Distributed SystemsDeadlock Detection in Distributed Systems
Deadlock Detection in Distributed Systems
 
Deadlocks
Deadlocks Deadlocks
Deadlocks
 
Deadlock- Operating System
Deadlock- Operating SystemDeadlock- Operating System
Deadlock- Operating System
 
Errors (Concurrency)
Errors (Concurrency)Errors (Concurrency)
Errors (Concurrency)
 
Mca ii os u-3 dead lock & io systems
Mca  ii  os u-3 dead lock & io systemsMca  ii  os u-3 dead lock & io systems
Mca ii os u-3 dead lock & io systems
 
Deadlock
DeadlockDeadlock
Deadlock
 
Cs problem [repaired]
Cs problem [repaired]Cs problem [repaired]
Cs problem [repaired]
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating System
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock
DeadlockDeadlock
Deadlock
 
Lecture5
Lecture5Lecture5
Lecture5
 
Operating system Dead lock
Operating system Dead lockOperating system Dead lock
Operating system Dead lock
 
Deadlock detection & prevention
Deadlock detection & preventionDeadlock detection & prevention
Deadlock detection & prevention
 
Deadlock Presentation
Deadlock PresentationDeadlock Presentation
Deadlock Presentation
 
Os deadlock
Os deadlockOs deadlock
Os deadlock
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock
DeadlockDeadlock
Deadlock
 
Dead lock
Dead lockDead lock
Dead lock
 
Ch8 OS
Ch8 OSCh8 OS
Ch8 OS
 

Andere mochten auch

Lecture 7: Definite Clause Grammars
Lecture 7: Definite Clause GrammarsLecture 7: Definite Clause Grammars
Lecture 7: Definite Clause GrammarsCS, NcState
 
Os4 2
Os4 2Os4 2
Os4 2issbp
 
Os2 2
Os2 2Os2 2
Os2 2issbp
 
Os5 2
Os5 2Os5 2
Os5 2issbp
 
Class5
 Class5 Class5
Class5issbp
 
Ch11 input output systems
Ch11 input output systemsCh11 input output systems
Ch11 input output systemsissbp
 
Class9
 Class9 Class9
Class9issbp
 
Theory of Automata and formal languages Unit 5
Theory of Automata and formal languages Unit 5Theory of Automata and formal languages Unit 5
Theory of Automata and formal languages Unit 5Abhimanyu Mishra
 
Os10 2
Os10 2Os10 2
Os10 2issbp
 
Automated Web Service Change Management (AWSCM) A tool published at IEEE Clou...
Automated Web Service Change Management (AWSCM) A tool published at IEEE Clou...Automated Web Service Change Management (AWSCM) A tool published at IEEE Clou...
Automated Web Service Change Management (AWSCM) A tool published at IEEE Clou...Animesh Chaturvedi
 
Pattern detection in mealy machine
Pattern detection in mealy machinePattern detection in mealy machine
Pattern detection in mealy machineAnimesh Chaturvedi
 
Class6
 Class6 Class6
Class6issbp
 
0227 regularlanguages
 0227 regularlanguages 0227 regularlanguages
0227 regularlanguagesissbp
 
Software Engineering Unit 1
Software Engineering Unit 1Software Engineering Unit 1
Software Engineering Unit 1Abhimanyu Mishra
 

Andere mochten auch (20)

Os2
Os2Os2
Os2
 
Lecture 7: Definite Clause Grammars
Lecture 7: Definite Clause GrammarsLecture 7: Definite Clause Grammars
Lecture 7: Definite Clause Grammars
 
Os4 2
Os4 2Os4 2
Os4 2
 
Os2 2
Os2 2Os2 2
Os2 2
 
Os4
Os4Os4
Os4
 
Os5 2
Os5 2Os5 2
Os5 2
 
Class5
 Class5 Class5
Class5
 
Ch11 input output systems
Ch11 input output systemsCh11 input output systems
Ch11 input output systems
 
Class9
 Class9 Class9
Class9
 
Design1
Design1Design1
Design1
 
Os5
Os5Os5
Os5
 
Theory of Automata and formal languages Unit 5
Theory of Automata and formal languages Unit 5Theory of Automata and formal languages Unit 5
Theory of Automata and formal languages Unit 5
 
Os10 2
Os10 2Os10 2
Os10 2
 
Cspc final
Cspc finalCspc final
Cspc final
 
Automated Web Service Change Management (AWSCM) A tool published at IEEE Clou...
Automated Web Service Change Management (AWSCM) A tool published at IEEE Clou...Automated Web Service Change Management (AWSCM) A tool published at IEEE Clou...
Automated Web Service Change Management (AWSCM) A tool published at IEEE Clou...
 
Pattern detection in mealy machine
Pattern detection in mealy machinePattern detection in mealy machine
Pattern detection in mealy machine
 
Os3
Os3Os3
Os3
 
Class6
 Class6 Class6
Class6
 
0227 regularlanguages
 0227 regularlanguages 0227 regularlanguages
0227 regularlanguages
 
Software Engineering Unit 1
Software Engineering Unit 1Software Engineering Unit 1
Software Engineering Unit 1
 

Ähnlich wie Os6 2

Ähnlich wie Os6 2 (20)

Deadlock Detection Algorithm
Deadlock Detection AlgorithmDeadlock Detection Algorithm
Deadlock Detection Algorithm
 
Galvin-operating System(Ch8)
Galvin-operating System(Ch8)Galvin-operating System(Ch8)
Galvin-operating System(Ch8)
 
Operating System Deadlock Galvin
Operating System  Deadlock GalvinOperating System  Deadlock Galvin
Operating System Deadlock Galvin
 
Chapter5_Deadlock.pptx
Chapter5_Deadlock.pptxChapter5_Deadlock.pptx
Chapter5_Deadlock.pptx
 
OS Presentation 1 (1).pptx
OS Presentation 1 (1).pptxOS Presentation 1 (1).pptx
OS Presentation 1 (1).pptx
 
Ch8: Deadlocks
Ch8: DeadlocksCh8: Deadlocks
Ch8: Deadlocks
 
CH07.pdf
CH07.pdfCH07.pdf
CH07.pdf
 
7308346-Deadlock.pptx
7308346-Deadlock.pptx7308346-Deadlock.pptx
7308346-Deadlock.pptx
 
Sucet os module_3_notes
Sucet os module_3_notesSucet os module_3_notes
Sucet os module_3_notes
 
Operating System
Operating SystemOperating System
Operating System
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock_SVVSDM_DWD
Deadlock_SVVSDM_DWDDeadlock_SVVSDM_DWD
Deadlock_SVVSDM_DWD
 
O ssvv62015
O ssvv62015O ssvv62015
O ssvv62015
 
A petri-net
A petri-netA petri-net
A petri-net
 
Inside LoLA - Experiences from building a state space tool for place transiti...
Inside LoLA - Experiences from building a state space tool for place transiti...Inside LoLA - Experiences from building a state space tool for place transiti...
Inside LoLA - Experiences from building a state space tool for place transiti...
 
OS-Part-06.pdf
OS-Part-06.pdfOS-Part-06.pdf
OS-Part-06.pdf
 
When Streaming Needs Batch With Konstantin Knauf | Current 2022
When Streaming Needs Batch With Konstantin Knauf | Current 2022When Streaming Needs Batch With Konstantin Knauf | Current 2022
When Streaming Needs Batch With Konstantin Knauf | Current 2022
 
6. Deadlock.ppt
6. Deadlock.ppt6. Deadlock.ppt
6. Deadlock.ppt
 
Os unit 4
Os unit 4Os unit 4
Os unit 4
 

Mehr von issbp

Os10
Os10Os10
Os10issbp
 
Os9 2
Os9 2Os9 2
Os9 2issbp
 
Os8 2
Os8 2Os8 2
Os8 2issbp
 
Os7 2
Os7 2Os7 2
Os7 2issbp
 
Os3 2
Os3 2Os3 2
Os3 2issbp
 
Class8
 Class8 Class8
Class8issbp
 
Class7
 Class7 Class7
Class7issbp
 
Class4
 Class4 Class4
Class4issbp
 
Class3
 Class3 Class3
Class3issbp
 
Class2
 Class2 Class2
Class2issbp
 
Class1
 Class1 Class1
Class1issbp
 

Mehr von issbp (14)

Os10
Os10Os10
Os10
 
Os9 2
Os9 2Os9 2
Os9 2
 
Os9
Os9Os9
Os9
 
Os8 2
Os8 2Os8 2
Os8 2
 
Os8
Os8Os8
Os8
 
Os7 2
Os7 2Os7 2
Os7 2
 
Os7
Os7Os7
Os7
 
Os3 2
Os3 2Os3 2
Os3 2
 
Class8
 Class8 Class8
Class8
 
Class7
 Class7 Class7
Class7
 
Class4
 Class4 Class4
Class4
 
Class3
 Class3 Class3
Class3
 
Class2
 Class2 Class2
Class2
 
Class1
 Class1 Class1
Class1
 

Os6 2

  • 1. Operating Systems Principles Process Management and Coordination Lecture 6: Deadlocks 主講人:虞台文
  • 2.
  • 3. Operating Systems Principles Process Management and Coordination Lecture 6: Deadlocks Deadlocks with Reusable and Consumable Resources
  • 5.
  • 6.
  • 7.
  • 8. Example (File Sharing) p1: ... open(f1,w); open(f2,w); ... p2: ... open(f2,w); open(f1,w); ... Deadlock when executed concurrently
  • 9. Example (Message Passing) p1: ... if( C )send(p2,m); while(1){ recv(p3,m); ... send(p2,m); } Deadlock when C is not true p2: ... while(1){ recv(p1,m); ... send(p3,m); } p3: ... while(1){ recv(p2,m); ... send(p1,m); } Assume that send / recv are blocking operations.
  • 10.
  • 11.
  • 12. Operating Systems Principles Process Management and Coordination Lecture 6: Deadlocks Approaches to the Deadlock Problem
  • 13.
  • 14. Operating Systems Principles Process Management and Coordination Lecture 6: Deadlocks System Model
  • 15.
  • 16. State Transitions by p 1 Process S 0 S 1 S 2 S 3 The state transition diagram described below is not complete . The actual number of states depends on possible operations of processes. R p 1 p 2 R p 1 p 2 R p 1 p 2 R p 1 p 2 Request R (by p 1 ) Acquire R (by p 1 ) Release R (by p 1 )
  • 17.
  • 18.
  • 19. Example p 1 and p 2 both need R 1 and R 2 . R 1 R 2 p 1 p 2 p1: Request( R1 ); Request( R2 ); Release( R2 ); Release( R1 ); p2: Request( R2 ); Request( R1 ); Release( R1 ); Release( R2 );
  • 20. Example p1: Request( R1 ); Request( R2 ); Release( R2 ); Release( R1 ); p2: Request( R2 ); Request( R1 ); Release( R1 ); Release( R2 );
  • 21. Example p1: Request( R1 ); Request( R2 ); Release( R2 ); Release( R1 ); p2: Request( R2 ); Request( R1 ); Release( R1 ); Release( R2 );
  • 22. Example p1: Request( R1 ); Request( R2 ); Release( R2 ); Release( R1 ); p2: Request( R2 ); Request( R1 ); Release( R1 ); Release( R2 );
  • 23. Example p1: Request( R1 ); Request( R2 ); Release( R2 ); Release( R1 ); p2: Request( R2 ); Request( R1 ); Release( R1 ); Release( R2 );
  • 24. Example R 1 R 2 p 1 p 2
  • 25. Example p 1 is blocked. p 2 is blocked.
  • 26. Example A deadlock state. No state is safe since the deadlock state is always reachable .
  • 27. Necessary Condition for Deadlock A cycle in the resource graph is a necessary condition for deadlock.
  • 28. Operating Systems Principles Process Management and Coordination Lecture 6: Deadlocks Deadlock Detection
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52. Operating Systems Principles Process Management and Coordination Lecture 6: Deadlocks Recovery from Deadlock
  • 53.
  • 54. Operating Systems Principles Process Management and Coordination Lecture 6: Deadlocks Dynamic Deadlock Avoidance
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60. The Banker’s Algorithm p 1 p 2 p 3 R 1 R 2
  • 61. The Banker’s Algorithm Which of the requests can safely be granted ? Can p 1  R 1 be safely be granted ? Can p 2  R 1 be safely be granted ? Can p 3  R 1 be safely be granted ? R 1 R 2 p 1 p 2 p 3
  • 62. The Banker’s Algorithm Can p 1  R 1 be safely be granted ? Can p 2  R 1 be safely be granted ? Can p 3  R 1 be safely be granted ? Temporarily grant Can such an RAG be completely reducible? R 1 R 2 p 1 p 2 p 3
  • 63. The Banker’s Algorithm Can p 1  R 1 be safely be granted ? Can p 2  R 1 be safely be granted ? Can p 3  R 1 be safely be granted ? p 1 p 2 p 3 Temporarily grant Can such an RAG be completely reducible?  R 1 R 2
  • 64. The Banker’s Algorithm Can p 1  R 1 be safely be granted ? Can p 2  R 1 be safely be granted ? Can p 3  R 1 be safely be granted ? granted Can such an RAG be completely reducible?  R 1 R 2 p 1 p 2 p 3
  • 65. The Banker’s Algorithm Can p 1  R 1 be safely be granted ? Can p 2  R 1 be safely be granted ? Can p 3  R 1 be safely be granted ?  R 1 R 2 p 1 p 2 p 3
  • 66. The Banker’s Algorithm Can p 1  R 1 be safely be granted ? Can p 2  R 1 be safely be granted ? Can p 3  R 1 be safely be granted ? Can such an RAG be completely reducible? Temporarily grant   R 1 R 2 p 1 p 2 p 3
  • 67. The Banker’s Algorithm Can p 1  R 1 be safely be granted ? Can p 2  R 1 be safely be granted ? Can p 3  R 1 be safely be granted ?   not granted R 1 R 2 p 1 p 2 p 3
  • 68. The Banker’s Algorithm Can p 1  R 1 be safely be granted ? Can p 2  R 1 be safely be granted ? Can p 3  R 1 be safely be granted ?   R 1 R 2 p 1 p 2 p 3
  • 69. The Banker’s Algorithm Can p 1  R 1 be safely be granted ? Can p 2  R 1 be safely be granted ? Can p 3  R 1 be safely be granted ?   Can such an RAG be completely reducible? Temporarily grant R 1 R 2 p 1 p 2 p 3
  • 70. The Banker’s Algorithm Can p 1  R 1 be safely be granted ? Can p 2  R 1 be safely be granted ? Can p 3  R 1 be safely be granted ?   p 1 p 2 p 3 Can such an RAG be completely reducible? Temporarily grant  R 1 R 2
  • 71. The Banker’s Algorithm Can p 1  R 1 be safely be granted ? Can p 2  R 1 be safely be granted ? Can p 3  R 1 be safely be granted ?    granted p 1 p 2 p 3 R 1 R 2
  • 72.
  • 73. Operating Systems Principles Process Management and Coordination Lecture 6: Deadlocks Deadlock Prevention
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.