Docsity

Resource Allocation and Deadlock Prevention, Lecture notes of Operating Systems

Partial preview of the text

Download Resource Allocation and Deadlock Prevention and more Lecture notes Operating Systems in PDF only on Docsity!

OPERATING SYSTEMS

CS

Spring 2018

Deadlocks

Chapter 7

Resource Allocation and Deallocation When a process needs resources, it will normally follow the sequence:

  1. Request a number of instances of one or more resource types. If the resource units requested are not available, then process must wait
  2. Acquire the resource(s), the OS allocates resources
  3. Use the resource(s) for a finite period.
  4. Release the resource(s).

Multiple Resource Allocation Problem  Several processes may compete for multiple resources  If the allocation of multiple resources to processes is not done with proper synchronization, deadlock might occur  This waiting state is much more involved than starvation

Deadlock Problem A state of the computer system is which:  A set of blocked (suspended) processes  Each process holding one or more resources  Processes waiting to acquire one or more resources held by other processes

Deadlock – General Definition  A set of processes is in a deadlock state when every processes in the set is waiting for an event that can only be caused by another process in the set.  The events of interest are:  allocations of resources  release of resources  The resources are: CPU cycles, memory spaces, files, I/O devices in the computer system.

Disadvantage Of Deadlock  Deadlocked processes can never complete execution because they are waiting indefinitely  System resources are tied up because they are held by deadlocked processes.  Deadlocks are undesirable because they normally slow down a system

Deadlock Result Both processes are blocked, they cannot proceed.

Conditions For Deadlock A deadlock arises if four conditions hold simultaneously in a system:  Mutual exclusion: only one process at a time can use a resource.  Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes.

About These Conditions These conditions are necessary but not sufficient for deadlock to occur.

Resource Allocation Graph

A resource allocation graph shows the relationships between processes and resources. It consists of the following components:  A set of processes P = { P0, P1, …., Pi,…., Pn }  A set of resource types, R = { R0, R1, …,Rj, ..,Rm }  A set of directed edges

A Resource Allocation Graph

Resource Allocation Graph with Cycle

Analysis Resource Allocation Graph  If the graph contains no cycles, no deadlock exists.  If the graph contain cycles  if each resource type has only 1 instance, then a deadlock exists.  otherwise, a deadlock may exist.

Handling Deadlocks General approaches, the OS can:  Ensure that the system will never enter a deadlock state.  Allow the system to enter a deadlock state and then recover.  Ignore the problem and pretend that deadlocks never occur in the system.