Monday, 19 March 2012

Safe, Unsafe , Deadlock State


Basic Facts


  • If a system is in safe state Þ no deadlocks.
  • If a system is in unsafe state Þ possibility of deadlock.
  • Avoidance Þ ensure that a system will never enter an unsafe state. 

Safe State


  • When a process requests an available resource, system must decide if immediate allocation leaves the system in a safe state.
  • System is in safe state if there exists a safe sequence of all processes. 
  • Sequence <P1, P2, …, Pn> is safe if for each Pi, the resources that Pi can still request can be satisfied by currently available resources + resources held by all the Pj, with j<I.
  1. If Pi resource needs are not immediately available, then Pi can wait until all Pj have finished.
  2. When Pj is finished, Pi can obtain needed resources, execute, return allocated resources, and terminate.
  3. When Pi terminates, Pi+1 can obtain its needed resources, and so on. 

Deadlock Avoidance


Requires that the system has some additional a priori information available.
  • Simplest and most useful model requires that each process declare the maximum number of resources of each type that it may need.
  • The deadlock-avoidance algorithm dynamically examines the resource-allocation state to ensure that there can never be a circular-wait condition.
  • Resource-allocation state is defined by the number of available and allocated resources, and the maximum demands of the processes.

Deadlock Prevention


Restrain the ways request can be made.
  • Mutual Exclusion – not required for sharable resources; must hold for nonsharable resources.
  • Hold and Wait – must guarantee that whenever a process requests a resource, it does not hold any other resources.
  1. Require process to request and be allocated all its resources before it begins execution, or allow process to request resources only when the process has none.
  2. Low resource utilization; starvation possible.
  • No Preemption – 
  1. If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released.
  2. Preempted resources are added to the list of resources for which the process is waiting.
  3. Process will be restarted only when it can regain its old resources, as well as the new ones that it is requesting.
  • Circular Wait – impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration.



Methods for Handling Deadlocks


  • 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; used by most operating systems, including UNIX.

Wednesday, 14 March 2012

Basic Facts


  • If graph contains no cycles Þ no deadlock.
  • If graph contains a cycle Þ 
  1. if only one instance per resource type, then deadlock.
  2. if several instances per resource type, possibility of deadlock.