Scheduling

Only available on StudyMode
  • Topic: Deadlock, Resource allocation, Resource
  • Pages : 7 (1111 words )
  • Download(s) : 194
  • Published : April 19, 2013
Open Document
Text Preview
Operating Systems

User OS Kernel & Device Drivers Interface Programs

Deadlock

Brian Mitchell (bmitchel@mcs.drexel.edu) Operating Systems

1

Deadlocks
• Computer resources are full of resources that can only be used by one process at a time • Unpredictable results can occur if two or more processes use the same resource at the same time • OS control this problem by arbitrating resource requests • OS grant exclusive access and manage access to system resources • By allowing processes to have exclusive access to resources problems may occur: – Starvation – Deadlock

Brian Mitchell (bmitchel@mcs.drexel.edu) Operating Systems

2

Deadlocks
• Deadlock can occur if two or more processes are competing for two or more common resources • Deadlock causes all processes involved in the deadlock to become permanently blocked – Each process is waiting on resources owned by other processes that are also deadlocked

• Deadlock may be difficult to detect
– Often timing sensitive

• What to do about deadlocks:
– – – – Understand them Model them Develop ways to detect them Develop ways to avoid them Brian Mitchell (bmitchel@mcs.drexel.edu) Operating Systems 3

Resources
• Deadlocks occur when processes have been granted exclusive access to resources – Resources include semaphores, devices, files, …

• Resources come in two types:
– Preemptive resource: A resources that can be taken away from a process without any ill effects. • Example: memory

– Non-preemptive resource: A resource that can not be taken safely away from a process • Example: printer

• Deadlocks generally involve non-preemptive resources • Deadlocks can be easily fixed with preemptive resources – Take resources away from one or more deadlocked processes Brian Mitchell (bmitchel@mcs.drexel.edu) Operating Systems 4

Using Resources
• Access to resources should follow the model presented when we discussed critical sections – Request the resource – Use the resource – Release the resource

• If a resource is not available when requested, the requesting process should block • It is often difficult to develop a program that can continue if needed resources are not available • This model relies on well-behaved processes – What happens if a process does not release resources

• Timeout?
Brian Mitchell (bmitchel@mcs.drexel.edu) Operating Systems 5

Conditions for Deadlock
A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set can cause • Conditions for deadlock: – Mutual exclusion condition. Each resources is either currently assigned to exactly one process or is available – Hold and wait condition. Processes currently holding resources granted earlier can request new resources – No preemption condition. Resources previously granted cannot be forcibly taken away from a process – Circular wait condition. There must be a circular chain of two or more processes where each is waiting for a resource held by the next member of the chain Brian Mitchell (bmitchel@mcs.drexel.edu) Operating Systems 6

Deadlock Modeling
• Deadlocks can be modeled by creating simple graphs.
– Circles are processes – Squares are resources – Edges represent a resource request or a resource being held by a process D C B D B Process A holds resource B Process C requests resource D Deadlock A

A

C

Brian Mitchell (bmitchel@mcs.drexel.edu) Operating Systems

7

Deadlock Modeling
• Draw all resources and processes • Add edges as resource requests and releases are requested • Check for a cycle in the graph to detect deadlock Process A: Request R, S; Release R, S Process B: Request S, T; Release S, T Process C: Request T, R; Release T, R

A R

B S

C T

A R

B S

C T

A R

B S

C T

A requests R B requests S C requests T

A requests S B requests T
Brian Mitchell (bmitchel@mcs.drexel.edu) Operating Systems

C requests R DEADLOCK
8

How To Deal With Deadlocks
•...
tracking img