Questions: Deadlock Prevention and Avoidance Strategies
5 questions to test your understanding
Score: 0 / 5
Question 1 Multiple Choice
A system assigns global numbers to all resources and requires processes to request resources only in increasing numeric order. Suppose process A holds resource 3 and wants resource 5, while process B holds resource 5 and wants resource 3. What happens?
AA deadlock occurs because A and B are waiting for each other's resources
BProcess B is blocked from requesting resource 3 because 3 < 5, preventing circular wait
CThe system detects the circular wait and kills one of the processes
DBoth processes proceed because their requests don't violate the ordering rule
Resource ordering prevents circular wait by making resource dependency graphs acyclic. A process holding resource i may only request resource j where j > i. Process B holds resource 5 and wants resource 3, but 3 < 5 — this request violates the ordering rule and is blocked. Because no process can request a lower-numbered resource than what it holds, no cycle can form: if A is waiting for something B holds, B must hold a higher-numbered resource, meaning B can only be waiting for something even higher-numbered, and no chain can loop back. Deadlock is structurally impossible.
Question 2 Multiple Choice
The Banker's algorithm denies a resource request even when the resources are currently available. Under what condition does this happen?
AWhen granting the request would leave the system with fewer than two free resources
BWhen the requesting process has not declared its maximum resource needs in advance
CWhen granting the request would leave the system in an unsafe state — no sequence exists in which all processes can complete
DWhen the request would cause the system's total allocated resources to exceed 80% of total capacity
The Banker's algorithm maintains a notion of 'safe state': a state where there exists at least one ordering of processes in which each can be granted its maximum remaining needs using available resources plus resources released by earlier processes in the sequence. If granting a request would leave the system in an unsafe state — even though the resources are currently free — the algorithm denies the request and makes the process wait. Resources being available is a necessary but not sufficient condition for granting a request; the system must also remain safe after the grant.
Question 3 True / False
Deadlock prevention and deadlock avoidance both break the circular-wait condition before it occurs.
TTrue
FFalse
Answer: False
False. Deadlock prevention may target any of the four necessary conditions (mutual exclusion, hold-and-wait, no preemption, circular wait) — resource ordering attacks circular wait specifically, but preventing hold-and-wait (atomic acquisition) attacks a different condition entirely. Deadlock avoidance (Banker's algorithm) does not break any necessary condition at all — it allows processes to request resources in any order and simply ensures the system stays in a safe state by selectively denying requests. The two strategies are conceptually different: prevention modifies system rules to make a condition impossible; avoidance dynamically monitors state to avoid dangerous allocations.
Question 4 True / False
Resource ordering (assigning global numbers and requiring increasing-order requests) is a deadlock prevention strategy that works by making circular wait impossible.
TTrue
FFalse
Answer: True
True. A cycle in the resource-allocation graph (which represents circular wait) requires at least two processes where A waits for a resource held by B and B waits for a resource held by A. With resource ordering, every 'waits-for' edge goes from a lower-numbered resource to a higher-numbered resource — so a chain can never loop back to its starting point. Cycles are structurally impossible, which means the circular-wait condition (one of the four necessary conditions for deadlock) can never be satisfied.
Question 5 Short Answer
What is the fundamental difference between deadlock prevention and deadlock avoidance as strategies, and why does that difference affect how much concurrency each permits?
Think about your answer, then reveal below.
Model answer: Prevention modifies system rules or program structure at design time to make at least one necessary deadlock condition impossible — for example, resource ordering makes circular wait structurally impossible regardless of runtime behavior. It is simple and low-overhead but often overly conservative: resource ordering may require programs to acquire resources in an unnatural sequence, and atomic acquisition (request-all-at-once) wastes resources by locking them before they're needed. Avoidance (Banker's algorithm) permits processes to request resources dynamically in any order but runs a safety check before every allocation, granting only requests that leave the system in a safe state. This allows more parallelism because resources are only withheld when they would actually lead to danger — but it requires processes to pre-declare maximum needs and adds per-allocation computational cost.
The deeper contrast is static vs. dynamic. Prevention is a structural constraint applied ahead of time; avoidance is a runtime monitor that watches system state. Prevention can be too broad (blocking valid request patterns that could never actually cause deadlock), while avoidance is more precise but more expensive and requires information (maximum resource demands) that may be unavailable or inaccurate in practice.