csi 400/500 operating systems spring 2009 lecture #17 –deadlocks wednesday, april 15 th

16
CSI 400/500 Operating Systems Operating Systems Spring 2009 Spring 2009 Lecture #17 –Deadlocks Lecture #17 –Deadlocks Wednesday, April 15 Wednesday, April 15 th th

Post on 19-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSI 400/500 Operating Systems Spring 2009 Lecture #17 –Deadlocks Wednesday, April 15 th

CSI 400/500 Operating CSI 400/500 Operating Systems Spring 2009Systems Spring 2009

Lecture #17 –DeadlocksLecture #17 –Deadlocks

Wednesday, April 15Wednesday, April 15thth

Page 2: CSI 400/500 Operating Systems Spring 2009 Lecture #17 –Deadlocks Wednesday, April 15 th

22

Deadlock is...Deadlock is...

Permanent blocking of at least two Permanent blocking of at least two processes competing for system processes competing for system resourcesresources

One process waiting on release of One process waiting on release of resource held by another, who is waiting resource held by another, who is waiting for different resource held by waiting for different resource held by waiting processprocess

Page 3: CSI 400/500 Operating Systems Spring 2009 Lecture #17 –Deadlocks Wednesday, April 15 th

33

Resource TypesResource Types

ReusableReusable Process holds resource and then releases for Process holds resource and then releases for

later reuse by other processeslater reuse by other processes Examples: buffer, processors, memory, data Examples: buffer, processors, memory, data

devicesdevices

Consumable Consumable Process creates and destroys resource Process creates and destroys resource Example: message blocksExample: message blocks

Page 4: CSI 400/500 Operating Systems Spring 2009 Lecture #17 –Deadlocks Wednesday, April 15 th

44

Conditions for DeadlockConditions for Deadlock

Mutual Exclusivity : only one process Mutual Exclusivity : only one process holds resource at a timeholds resource at a time

Hold and wait : processes allowed to hold Hold and wait : processes allowed to hold resources while waitingresources while waiting

Non-preemptive processesNon-preemptive processes

Circular wait : processes in waitCircular wait : processes in wait

hold resources requested by hold resources requested by

othersothers

Page 5: CSI 400/500 Operating Systems Spring 2009 Lecture #17 –Deadlocks Wednesday, April 15 th

55

Simple SolutionSimple Solution

Each process releases resource Each process releases resource

before requesting anotherbefore requesting another

Not always possibleNot always possible Data integrity of referenced Data integrity of referenced

resourceresource Dependent data or resourcesDependent data or resources

Page 6: CSI 400/500 Operating Systems Spring 2009 Lecture #17 –Deadlocks Wednesday, April 15 th

66

Determining Deadlock Determining Deadlock LikelihoodLikelihood

Resource Allocation GraphResource Allocation Graph Shows processes, resources, and who holds Shows processes, resources, and who holds

or requests resources.or requests resources.Rectangle is resource, circle is processRectangle is resource, circle is process

Arrow from resource to process denotes holdArrow from resource to process denotes hold

�� Arrow from process to resource denotes Arrow from process to resource denotes

requestrequest

��

Page 7: CSI 400/500 Operating Systems Spring 2009 Lecture #17 –Deadlocks Wednesday, April 15 th

77

Relieving Deadlock at Resource Relieving Deadlock at Resource LevelLevel

Multiple imagesMultiple images Some resources (like database tables) allow Some resources (like database tables) allow

multiple images, so that multiple processes multiple images, so that multiple processes can use itcan use it

Only works for read accessOnly works for read accessMultiple read locks possible, only one write lockMultiple read locks possible, only one write lock

Demonstrated on Resource Allocation Graph Demonstrated on Resource Allocation Graph by multiple dotsby multiple dots

Read often denoted by solid arrowhead and Read often denoted by solid arrowhead and dot, while write with opendot, while write with open

Page 8: CSI 400/500 Operating Systems Spring 2009 Lecture #17 –Deadlocks Wednesday, April 15 th

88

Preventing DeadlockPreventing Deadlock

Total requestTotal request Process requests all resources needed before Process requests all resources needed before

proceedingproceeding Prevents Hold and Wait conditionPrevents Hold and Wait condition Could starve resource heavy processesCould starve resource heavy processes

Page 9: CSI 400/500 Operating Systems Spring 2009 Lecture #17 –Deadlocks Wednesday, April 15 th

99

Preventing Deadlock, contPreventing Deadlock, cont

Single Write LockSingle Write Lock Allow a process to hold only one Allow a process to hold only one

write lockwrite lock Prevents Hold and WaitPrevents Hold and Wait Could cause excessive wait if process holding Could cause excessive wait if process holding

write lock holds it for long timewrite lock holds it for long time

PreemptionPreemption Insisting all process can be preemptedInsisting all process can be preempted Only practical for resources easily saved and Only practical for resources easily saved and

restored, like processorsrestored, like processors

Page 10: CSI 400/500 Operating Systems Spring 2009 Lecture #17 –Deadlocks Wednesday, April 15 th

1010

Preventing Deadlock, contPreventing Deadlock, cont

Resource OrderingResource Ordering Resources of similar type must be allocated in Resources of similar type must be allocated in

orderorder Release all existing locks to cycle back to Release all existing locks to cycle back to

beginningbeginning Prevents circular waitPrevents circular wait

Page 11: CSI 400/500 Operating Systems Spring 2009 Lecture #17 –Deadlocks Wednesday, April 15 th

1111

Deadlock AvoidanceDeadlock Avoidance

Doesn’t restrict processes or resourcesDoesn’t restrict processes or resources

Analyzes situations to prevent the Analyzes situations to prevent the simultaneous occurrence of all conditionssimultaneous occurrence of all conditions

Two methods:Two methods: Process DenialProcess Denial Resource Allocation DenialResource Allocation Denial

Page 12: CSI 400/500 Operating Systems Spring 2009 Lecture #17 –Deadlocks Wednesday, April 15 th

1212

Process DenialProcess Denial

Works with resource claimsWorks with resource claims

Processes have maximum resource claimProcesses have maximum resource claim

No process granted resources that exceed No process granted resources that exceed original claimoriginal claim

No process set to Ready if their maximum No process set to Ready if their maximum resource claim + resource claim of resource claim + resource claim of processes in system exceeds maximum processes in system exceeds maximum resource allocationresource allocation

Page 13: CSI 400/500 Operating Systems Spring 2009 Lecture #17 –Deadlocks Wednesday, April 15 th

1313

PitfallsPitfalls

Assumes processes will request maximum Assumes processes will request maximum resources at same timeresources at same time

Prevents initiation of many processesPrevents initiation of many processes

Page 14: CSI 400/500 Operating Systems Spring 2009 Lecture #17 –Deadlocks Wednesday, April 15 th

1414

Resource Allocation DenialResource Allocation Denial

Deny resources to processes who could Deny resources to processes who could cause deadlockcause deadlock

Expands Allocation and Claim numbers from Expands Allocation and Claim numbers from Process Denial, but allows processes to Process Denial, but allows processes to beginbegin

Works with Remaining and Available Works with Remaining and Available resource vectorsresource vectors

Processes through safe state until unsafe Processes through safe state until unsafe state detectedstate detected

Page 15: CSI 400/500 Operating Systems Spring 2009 Lecture #17 –Deadlocks Wednesday, April 15 th

1515

Deadlock DetectionDeadlock Detection

Check each resource requestCheck each resource request

Demands that a request set maintainedDemands that a request set maintained

Request set lists processes with Request set lists processes with outstanding requests for resourcesoutstanding requests for resources

When circular wait discovered, determine When circular wait discovered, determine deadlocked resource and suspend active deadlocked resource and suspend active process process

Page 16: CSI 400/500 Operating Systems Spring 2009 Lecture #17 –Deadlocks Wednesday, April 15 th

1616

Integrated StrategyIntegrated Strategy

Group resources into classesGroup resources into classes

Use linear orderingUse linear ordering

Maintain at least request and allocation Maintain at least request and allocation matrices, if not maximum claim matrixmatrices, if not maximum claim matrix