DEV Community

loading...

DEADLOCK PREVENTION AND AVOIDANCE

D-Shailesh-Reddy
・2 min read

Deadlock Prevention and Avoidance

Deadlock characteristics

  1. Mutual Exclusion
  2. Hold and wait
  3. No preemption
  4. Circular wait

Deadlocks can be prevented by eliminating these conditions

Eliminating Mutual exclusion
It is not possible to do this as some resources such as the drivers and printers
are inherently non-shareable.

Eliminating Hold and wait
Allocate all necessary resources to the process before it begins to run; this
eliminates the hold and wait conditions, but it results in low system
utilization. For instance, if a process needs printing at a later time and we have
allocated a printer before the start of its execution, the printer will be blocked
until the process is completed.
This process will make new requests for a resource after releasing set of
resources but this may lead to starvation

Eliminating No preemption
Preempt resources from the process when it is required by other high priority
process

Eliminate Circular wait
A numerical number will be allocated to each resource. A process may request
that the number of resources be increased or decreased. For example, if P1 is
given R5 resources, the next time P1 requests R4, R3, or any other resource
less than R5, the request will be denied; only requests for resources greater
than R5 will be granted.

Deadlock avoidance
This can be done with Banker's Algorithm
Bankers Algorithm:
Bankers’ Algorithm is a resource allocation and deadlock avoidance algorithm
that examines all resource requests made by systems, checks for the safe state,
and makes the request if the system remains in the safe state after approving
the request. If there is no safe state, the request is denied.

Inputs required for Bankers algorithm:

  1. maximum need or resources required by each process
  2. The currently allocated resources by each process
  3. Free resources available in the system

Request for the resource will only be granted when:

  1. If the request made by the process is </<= freely available resource in the system
  2. If the request made by the process is </<= maximum amount of resources required for the process

Discussion (0)

Forem Open with the Forem app