0% found this document useful (0 votes)
13 views8 pages

Deadlocks

Deadlocks pdf

Uploaded by

nayanaminajagi34
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views8 pages

Deadlocks

Deadlocks pdf

Uploaded by

nayanaminajagi34
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Deadlocks

Nayana c Minajagi
3PD21CS051
Necessary conditions
1. Mutual exclusion. At least one resource must be held in a nonsharable mode; that
is, only one process at a time can use the resource. If another process requests that
resource, the requesting process must be delayed until the resource has been
released.
2. Hold and wait. A process must be holding at least one resource and waiting to
acquire additional resources that are currently being held by other processes.
3. No preemption. Resources cannot be preempted; that is, a resource can be
released only voluntarily by the process holding it, after that process has completed
its task.
4. Circular wait. A set {P0, P1, ..., Pn} of waiting processes must exist such that P0 is
waiting for a resource held by P1, P1 is waiting for a resource held by P2, ..., Pn−1 is
waiting for a resource held by Pn, and Pn is waiting for a resource held by P0.
Resource allocation graph
Deadlocks can be described more precisely in terms of a directed graph called a
system resource-allocation graph. This graph consists of a set of vertices V and a
set of edges E. The set of vertices V is partitioned into two different types of
nodes: P = {P1, P2, ..., Pn}, the set consisting of all the active processes in the
system, and R = {R1, R2, ..., Rm}, the set consisting of all resource types in the
system.
• Resourceinstances:
◦ One instance of resource type R1
◦ Two instances of resource type R2 ◦ One instance of resource type R3
◦ Three instances of resource type R4
• Processstates:
◦ Process P1 is holding an instance of resource type R2 and is waiting for
an instance of resource type R1.
◦ Process P2 is holding an instance of R1 and an instance of R2 and is
waiting for an instance of R3.
◦ Process P3 is holding an instance of R3.
Methods for handling deadlocks
• We can use a protocol to prevent or avoid deadlocks, ensuring that the
system will never enter a deadlock state.
• We can ignore the problem altogether and pretend that deadlocks never occur in the
system
>we can allow a system to enter in a deadlock state,detect it and recover
.Deadlock avoidance requires that the operating system be given additional
information in advance concerning which resources a process will request and use
during its lifetime. With this additional knowledge, the operating system can decide
for each request whether or not the process should wait.
Bankers algorithm
The resource-allocation-graph algorithm is not applicable to a resource- allocation
system with multiple instances of each resource type. The deadlock- avoidance
algorithm that we describe next is applicable to such a system but is less efficient than
the resource-allocation graph scheme. This algorithm is commonly known as the
banker’s algorithm.
Data structures needed
• Available =a vector of length m indicates the number of available resources of each
type .if available[j] equals k then l instance of resource type Rj available

• Max. An n × m matrix defines the maximum demand of each process. If Max[i][j]


equals k, then process Pi may request at most k instances of resource type Rj .

• Allocation.An nxm matrix defines the number of resource of each type allocated to
each process. If Allocation[i][j] equals k, then process Pi is currently allocated k
instances of resource type Rj .

• Need. An n × m matrix indicates the remaining resource need of each process. If


Need[i][j] equals k, then process Pi may need k more instances of resource type Rj to
complete the task
Safety algorithm
1. Let Work and Finish be vectors of length m and n, respectively. Initialize Work =
Available and Finish[i] = false for i = 0, 1, ..., n − 1.

2. Find an index i such that both

a. Finish[i] == false

b. Needi ≤ Work

If no such i exists, go to step 4.

3. Work = Work + Allocationi Finish[i] = true

Go to step 2.

4. If Finish[i] == true for all i, then the system is in a safe state.

You might also like