0% found this document useful (0 votes)
20 views4 pages

Document

A2

Uploaded by

Waleed Håšhįm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views4 pages

Document

A2

Uploaded by

Waleed Håšhįm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Explore the concept of deadlocks, including their meaning,

characteristics, prevention strategies, and delve into understanding


the Banker's Algorithm:-

Deadlocks are situations in computer systems, particularly in the


context of operating systems and concurrent processing, where two or
more processes are unable to proceed because each one is waiting for
a resource held by another. Deadlocks can significantly affect system
performance, leading to processes being indefinitely stalled, so
understanding how they occur and how to prevent them is crucial.

1. Meaning of Deadlocks

A deadlock occurs when a set of processes is blocked because each


process is holding a resource and waiting to acquire a resource held by
another process.

In other words, the processes form a cycle of dependency where each


process in the cycle is waiting for a resource held by the next process
in the cycle.

2. Characteristics of Deadlocks

According to Coffman’s Conditions (also known as the Deadlock


Conditions), four conditions must hold simultaneously for a deadlock to
occur:
Mutual Exclusion: At least one resource must be held in a non-
shareable mode. If another process requests that resource, the
requesting process must wait until the resource is released.

Hold and Wait: A process holding at least one resource is waiting to


acquire additional resources held by other processes.

No Preemption: A resource cannot be forcibly taken from a process


holding it; the process must release the resource voluntarily.

Circular Wait: A set of processes is in a circular chain where each


process is waiting for a resource that the next process in the chain
holds.

If all four of these conditions are true, a deadlock can occur.

3. Deadlock Prevention Strategies

Preventing deadlocks involves ensuring that at least one of the four


Coffman Conditions does not hold. Here are some strategies:

Mutual Exclusion: Reduce non-shareable resources where possible. For


example, using read-only access where feasible can reduce the need
for mutual exclusion.

Hold and Wait: Require processes to request all needed resources at


once, preventing a process from holding onto resources while waiting
for others. Alternatively, processes can be required to release all
resources if they must wait for additional ones.
No Preemption: Allow resources to be forcibly taken from a process if it
needs to wait for others. For instance, if a process holding a resource is
required to wait, the system can forcibly release the resource and
assign it to the waiting process.

Circular Wait: Impose an ordering on resource types, and require that


processes request resources in an increasing order of enumeration.
This prevents circular chains from forming.

4. The Banker's Algorithm

The Banker's Algorithm is a deadlock avoidance algorithm developed


by Edsger Dijkstra. It is particularly useful in systems where resources
are allocated dynamically, and multiple instances of each resource
type are available. Here’s how it works:

Concept: The algorithm considers each process's maximum resource


needs at the start, along with the current allocation and availability of
resources. It then evaluates whether allocating resources to a
particular process will leave the system in a safe state.

Safe State: A state is safe if the system can allocate resources in some
order, such that every process can eventually complete and release its
resources back to the system.

Algorithm Steps:

1. Initialize with maximum need, allocation, and available resources.


2. Request resources by a process: Check if the request can be granted
while leaving the system in a safe state.

3. If granting the request still results in a safe state, allocate the


resources.

4. If not, deny the request and make the process wait.

Example: Consider a system with three resource types and five


processes, each with a maximum demand and current allocation. The
Banker's Algorithm checks if fulfilling a new resource request would
lead to a safe sequence, allowing all processes to finish. If yes, the
request is granted; if not, it’s denied, preventing potential deadlocks.

In essence, the Banker's Algorithm works proactively to prevent


deadlocks by ensuring that the system remains in a safe state with
respect to resource allocation. While it can effectively prevent
deadlocks, it requires prior knowledge of each process's maximum
needs, which might not always be feasible.

You might also like