Operating Systems Tutorial 2 & 16 Michael Tnzer os-tut@nhng.de - - PowerPoint PPT Presentation

operating systems
SMART_READER_LITE
LIVE PREVIEW

Operating Systems Tutorial 2 & 16 Michael Tnzer os-tut@nhng.de - - PowerPoint PPT Presentation

Review RAGs & WFGs Deadlocks Deadlock Avoidance Searching for Deadlocks Finish Operating Systems Tutorial 2 & 16 Michael Tnzer os-tut@nhng.de http://os-tut.nhng.de Calendar Week 50 OS-Tutorial Week 50 Michael Tnzer


slide-1
SLIDE 1

Review RAGs & WFGs Deadlocks Deadlock Avoidance Searching for Deadlocks Finish

Operating Systems

Tutorial 2 & 16 Michael Tänzer

  • s-tut@nhng.de

http://os-tut.nhng.de

Calendar Week 50

OS-Tutorial – Week 50 Michael Tänzer

slide-2
SLIDE 2

Review RAGs & WFGs Deadlocks Deadlock Avoidance Searching for Deadlocks Finish

Outline

1

Review

2

RAGs & WFGs RAGs WFGs Transformations

3

Deadlocks Prerequisites

4

Deadlock Avoidance (Banker’s Algorithm)

5

Searching for Deadlocks

OS-Tutorial – Week 50 Michael Tänzer

slide-3
SLIDE 3

Review RAGs & WFGs Deadlocks Deadlock Avoidance Searching for Deadlocks Finish

True or False

Progress means that a process in it’s critical section will eventually leave it On a single processor system no special atomic instructions are needed interrupts enable/disable is enough. Spinlocks are always useless as they’re doing nothing useful while waiting they should be replaced by blocking locks or semaphores.

OS-Tutorial – Week 50 Michael Tänzer

slide-4
SLIDE 4

Review RAGs & WFGs Deadlocks Deadlock Avoidance Searching for Deadlocks Finish RAGs

Vertices

Processes – represented by circles Resource types – represented by rectangles Multiple instances of a resource – a dot per instance inside the resource type vertex

OS-Tutorial – Week 50 Michael Tänzer

slide-5
SLIDE 5

Review RAGs & WFGs Deadlocks Deadlock Avoidance Searching for Deadlocks Finish RAGs

Edges

Request Edge Directed edge from a process to a resource vertex Indicates that the process wants to allocate a resource of that type Assignment Edge Directed edge from a specific instance

  • f a resource to a process vertex

Indicates that the resource is assigned to that process

OS-Tutorial – Week 50 Michael Tänzer

slide-6
SLIDE 6

Review RAGs & WFGs Deadlocks Deadlock Avoidance Searching for Deadlocks Finish RAGs

Does a cycle in a RAG always mean the a deadlock

  • ccurred?

Only if it involves resource types which only have a single instance

OS-Tutorial – Week 50 Michael Tänzer

slide-7
SLIDE 7

Review RAGs & WFGs Deadlocks Deadlock Avoidance Searching for Deadlocks Finish WFGs

What is a wait-for graph (WFG)?

A variant of a RAG Without resource vertices Edge from process Pi to Pj indicates that Pi is waiting for a resource held by Pj

OS-Tutorial – Week 50 Michael Tänzer

slide-8
SLIDE 8

Review RAGs & WFGs Deadlocks Deadlock Avoidance Searching for Deadlocks Finish Transformations

RAG → WFG

1

Remove resource vertices

2

Draw an edge from Pi to Pj if there existed an edge from Pi to R and from R to Pj for a resource R in the RAG

OS-Tutorial – Week 50 Michael Tänzer

slide-9
SLIDE 9

Review RAGs & WFGs Deadlocks Deadlock Avoidance Searching for Deadlocks Finish Transformations

RAG ← WFG

Not possible as the information which process is allocated/waiting for what resource is not present in a WFG.

OS-Tutorial – Week 50 Michael Tänzer

slide-10
SLIDE 10

Review RAGs & WFGs Deadlocks Deadlock Avoidance Searching for Deadlocks Finish Transformations

Can a WFG be drawn for a RAG with multiple instances per resource type?

P1 P2 P3 R1

Should the edge be drawn from P3 to P1 or to P2 ot to both? ⇒ Not possible

OS-Tutorial – Week 50 Michael Tänzer

slide-11
SLIDE 11

Review RAGs & WFGs Deadlocks Deadlock Avoidance Searching for Deadlocks Finish Transformations

What can a WFG be used for?

Deadlock detection Circle in WFG ⇒ deadlock occured

OS-Tutorial – Week 50 Michael Tänzer

slide-12
SLIDE 12

Review RAGs & WFGs Deadlocks Deadlock Avoidance Searching for Deadlocks Finish Prerequisites

Explain the necessary conditions for deadlocks

Give an example for how to prevent each of them

Mutual Exclusion Resources can’t be shared between processes (spooling) Hold and Wait A process already holding a ressource can wait to acquire another one (allocate resources atomically) No Preemtion Resources can’t be taken away from a process by force (save/load state) Circular Wait The WFG has a circle (order resources)

OS-Tutorial – Week 50 Michael Tänzer

slide-13
SLIDE 13

Review RAGs & WFGs Deadlocks Deadlock Avoidance Searching for Deadlocks Finish

What is a safe state?

All processes can run to completion Even if each process will request the maximum number of resources Processes which can’t be granted their request have to wait for others to terminate

OS-Tutorial – Week 50 Michael Tänzer

slide-14
SLIDE 14

Review RAGs & WFGs Deadlocks Deadlock Avoidance Searching for Deadlocks Finish

Task

(a) Allocation R1 R2 R3 R4 P1 1 2 P2 1 P3 1 3 5 4 P4 6 3 2 P5 1 4 (b) Max R1 R2 R3 R4 P1 1 2 P2 1 7 5 P3 2 3 5 6 P4 6 5 2 P5 6 5 6 (c) Available R1 R2 R3 R4 1 5 2

What is the content of the matrix ‘Need’? Is the system in a safe state? If P2 requests (0, 4, 2, 0) should it be granted?

OS-Tutorial – Week 50 Michael Tänzer

slide-15
SLIDE 15

Review RAGs & WFGs Deadlocks Deadlock Avoidance Searching for Deadlocks Finish

Code vulnerable to race conditions or deadlocks?

Spinlock s1, s2, s3 = FREE; int counter = 0; Thread1(){ if (counter == 0){ lock(s1); counter++; unlock(s1); } lock(s2); lock(s3); /* update some more data */ unlock(s3); unlock(s2); } Thread2(){ lock(s3); counter++; /* update some data */ if (counter == 2){ lock(s2); /* update some more data */ unlock(s2); } lock(s1); /* update even more data */ unlock(s3); unlock(s1); } OS-Tutorial – Week 50 Michael Tänzer

slide-16
SLIDE 16

Review RAGs & WFGs Deadlocks Deadlock Avoidance Searching for Deadlocks Finish

A Quick Survey

Write on an anonymous piece of paper: At least one thing you liked At least one thing that could be improved about the tutorial

OS-Tutorial – Week 50 Michael Tänzer

slide-17
SLIDE 17

Review RAGs & WFGs Deadlocks Deadlock Avoidance Searching for Deadlocks Finish

The End The End

OS-Tutorial – Week 50 Michael Tänzer