Sub topic 1
The Resource Model: Processes, Resources, and Instances
Deadlock analysis starts with a precise model of how processes use resources. A process is a running program. A resource type is a category of resource, such as a printer, a memory buffer, or a database lock. An instance is one available unit of a resource type.
For example, a system may contain:
| Resource type | Number of instances | Example |
|---|---|---|
| Printer | 2 | Two printers that can print independently |
| Tape drive | 1 | One shared tape drive |
| Memory buffer | 5 | Five identical buffer slots |
The instances of one resource type are usually treated as interchangeable. A process that needs one printer can use either printer instance.
Prerequisites
This chapter assumes that you understand processes, threads, critical sections, locks or semaphores, directed graphs, and basic vectors and matrices. You should also know that a process can be blocked while it waits for an event or resource.
How a process uses a resource
A process normally follows this sequence:
- It requests one or more resource instances.
- The operating system grants the request if the instances are available.
- The process uses the resources.
- The process releases the resources.
A request may be granted immediately, or the process may wait. A process that holds at least one resource while waiting for another is important in deadlock analysis.
Consider two processes and two resource types:
- P1 holds one instance of resource A and requests resource B.
- P2 holds one instance of resource B and requests resource A.
If A and B each have only one instance, neither process can continue. Each process holds something needed by the other.
Resource-allocation notation
A resource-allocation graph represents the current state.
- A process is shown as a circle, such as P1.
- A resource type is shown as a rectangle, such as R1.
- Each dot inside a resource rectangle represents one instance.
- An edge from a process to a resource means that the process is requesting an instance.
- An edge from a resource instance to a process means that the instance is currently allocated.
Suppose R1 has two instances. If one instance is assigned to P1 and P2 requests R1, the graph contains an allocation edge from one R1 instance to P1 and a request edge from P2 to R1.
The graph describes allocation, not the process's entire future. To reason about avoidance, the system may also record a process's maximum possible demand. This is the largest number of instances of each resource type that the process might need during its execution.
For each process and resource type, distinguish these values:
- Allocation: instances currently held.
- Maximum: the declared maximum demand.
- Need: additional instances still required.
Need is calculated element by element:
Need = Maximum − Allocation
For example, if a process has Allocation equal to (1, 0, 2) and Maximum equal to (3, 2, 2), its Need is (2, 2, 0). The process may still request two units of the first resource and two units of the second resource.
Why instances matter
A cycle in a resource-allocation graph has different meanings depending on the number of instances.
With exactly one instance of every resource type, a cycle means that the involved processes are deadlocked. With multiple instances, a cycle may only indicate a possibility of deadlock. Another free instance might satisfy a request and allow the cycle to disappear.
The resource model provides the data used by prevention, avoidance, and detection algorithms. The next step is to define exactly when blocked processes form a deadlock.
Exercise
A resource type R has three identical instances. P1 holds one instance and requests one more. P2 holds one instance and requests one more. Is this information alone enough to conclude that the system is deadlocked?
Show answer
No. One instance is still free, so either request may be satisfied. A deadlock conclusion requires the complete allocation and request state.