Deadlocks
Deadlocks
Resources:
In a computing system, processes require resources (e.g., CPU, memory, files, printers) to execute.
Resources can be classified into preemptable and non-preemptable resources based on whether they
can be forcibly taken from a process without causing issues.
Preemptable Resources
These are resources that can be taken away from a process without causing failure.
The system can safely reallocate these resources to another process.
Example:
CPU Cycles: A running process can be interrupted and scheduled again later.
Memory (RAM): The OS can swap out a process’s memory pages to disk and allocate
memory to another process.
Advantages of Preemptable Resources
✅Helps in deadlock recovery by allowing the system to take resources from one process and give
them to another.
✅ Allows for better resource management and efficient multitasking.
Challenges of Preemptable Resources
❌ Frequent preemption can lead to performance overhead (e.g., excessive context switching).
❌ Some resources, like cache memory, may suffer from performance degradation if frequently
swapped.
Non-Preemptable Resources
These are resources that cannot be forcibly taken away from a process without causing
failure.
The process must voluntarily release the resource before another process can use it.
Example:
Printers: If a document is being printed, preempting the printer would lead to a corrupted print job.
Files: If a process is writing to a file, forcefully stopping it can lead to data corruption.
Database Locks: A database transaction holding a lock cannot be interrupted without risking data
inconsistency.
Advantages of Non-Preemptable Resources
✅ Ensures data integrity and process stability.
✅ Reduces complexity in critical operations, such as printing or file handling.
Challenges of Non-Preemptable Resources
❌ Increases the risk of deadlocks because processes must wait for resources to be released.
❌ Requires careful resource management and deadlock handling techniques.
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. To decide
whether the current request can be satisfied or must be delayed, the system must consider the
resources currently available, the resources currently allocated to each process, and the future requests
and releases of each process.
Deadlock Prevention:
Deadlock prevention provides a set of methods to ensure that at least one of the necessary conditions
for deadlock (Mutual Exclusion, Hold and Wait, No Preemption, and Circular Wait) cannot hold.
These methods prevent deadlocks by constraining how resource requests are made.
1. Mutual Exclusion
The mutual exclusion condition must hold, meaning that at least one resource must be non-
sharable.
Sharable resources, in contrast, do not require mutually exclusive access and thus cannot be
involved in a deadlock.
Example:
Read-only files are sharable resources because multiple processes can access them
simultaneously.
A process never needs to wait for a sharable resource.
However, in general, we cannot prevent deadlocks by denying the mutual exclusion
condition because some resources are intrinsically non-sharable.