Deadlock, Livelock and Starvation
When a process waiting fails.
In multiprocessing, we find that there may be a process, or a number of processes that will need to make use of a particular resource available to the application, and all the time, we find that a process is waiting for a resource that is currently in use by another processes, making it unavailable.
If we ignore some very vital signs that a process is waiting for too long, the process will fail. We are likely to find our application in one of the three known scenarios.
Deadlock
When a process acquires or is assigned a resource, often once the process is complete or is done with the resource, it releases it so that any other processes that will require the resource has access to it.
For any reason, if one process (Process A) is waiting on a resource (Resource 2) being used by another process (Process B), and by chance resource 2 is not being released by Process B as it is also waiting on the release of a resource (Resource 1) being used by Process A, neither of the processes can make progress to complete, or is stuck on waiting. We find our program in what is called deadlock.
There are four key conditions which need to be met in order for deadlock to occur:
- At least one resource needs to be held by a process in a non-sharable mode, thus any other process requesting that particular resource will need to wait. This is known as Mutual Exclusion.
- A process must hold one resource and attempts to request additional resources that are currently held by another process. We call this hold and wait
- A resource for any reason cannot be forcefully released from a process, typically seen when a process is expected to voluntarily release the resource once its process conditions are satisfied. We say that there are no preemptions
- A set of process' are in such a way that the following process is waiting for the current process to release a resource. This is called circular wait (such as the example provided above, however can have more than two processes waiting for the resource held by a previous process).
Livelock
Similar to deadlock, livelock occurs similarly, however takes into consideration the state of a given process where one process relies on another process and the resources.This means that prior to releasing a resource, a process will check the state of the next process and when it is inactive - pass the resource. When the other process is waiting on the current process to finish in order to use the process output and resources used by that process, we end up in Livelock
The above figure shows an example of lovelock. Both "Process A" and "Process B" need a common resource. Each process will check whether the other process is in an active state. If so, the resource will be passed to the other process. Where both the processes are inactive, they will keep passing the resource to one another indefinitely.
Starvation
This is caused when a process is unable to access a shared resource at all, because another process has occupied the resource for an excessive duration, resulting in the process not being able to make progress.
The above process illustrates how "Process A" is occupying a resource fully, and as a result, Process B and Process C do not have access to the resource at all, resulting in starvation.



Comments
Post a Comment