Consider a computer system with multiple shared resource types, with one instance per resource type. Each instance can be owned by only one process at a time. Owning and freeing of resources are done by holding a global lock . The following scheme is used to own a resource instance:
function OWNRESOURCE(Resource R)
Acquire lock L // a global lock
if R is available then
Acquire R
Release lock L
else
if R is owned by another process P then
Terminate P, after releasing all resources owned by P
Acquire R
Restart P
Release lock L
end if
end if
end function
Which of the following choice(s) about the above scheme is/are correct?
View worked solution
Answer: A;B;C
To determine which choices are correct, let us analyze the behavior of the OWNRESOURCE function and how it manages resources.
1. Deadlock Prevention (Option A)
A deadlock requires four necessary conditions: Mutual Exclusion, Hold and Wait, No Preemption, and Circular Wait.
- In this scheme, when a process requests a resource that is currently held by another process , the requesting process does not wait.
- Instead, it immediately terminates , forces the release of 's resources, acquires , and restarts .
- Since no process ever enters a waiting state for a resource, the Hold and Wait condition is eliminated, and a Circular Wait cannot form.
Therefore, deadlocks cannot occur. Option A is correct.
2. Livelock (Option B)
A livelock occurs when two or more processes continuously change their state in response to each other without making any forward progress.
- Consider two processes, and , and two resources, and .
- acquires and acquires .
- Now, requests . Since is held by , terminates , releases , acquires , and restarts .
- Before can complete its execution, the restarted requests . Since is held by , terminates , releases all of 's resources (including ), acquires , and restarts .
- This cycle of mutual termination and restart can continue indefinitely, preventing both processes from ever completing.
Therefore, the scheme may lead to livelock. Option B is correct.
3. Starvation (Option C)
Starvation occurs when a process is perpetually denied the resources or CPU time it needs to complete its execution.
- As shown in the livelock scenario, a process can be repeatedly terminated and restarted by other active processes before it can finish its task.
- Consequently, such a process will suffer from starvation.
Therefore, the scheme may lead to starvation. Option C is correct.
4. Mutual Exclusion (Option D)
Mutual exclusion means that a resource instance can be held by at most one process at any given time.
- When a process requests an already-owned resource , the owner is terminated, and all of 's resources are released first before the requesting process acquires .
- Thus, at any instant, no resource is owned by more than one process.
Therefore, mutual exclusion is not violated. Option D is incorrect.
Free practice · Your answers on this page are not saved.
