Deadlocks are a set of blocked processes each holding a resource and waiting to acquire a resource held by another process.
How to avoid Deadlocks
Deadlocks can be avoided by avoiding at least one of the four conditions because all these four conditions are required simultaneously to cause deadlock.
Mutual Exclusion
Each resource is either currently assigned to exactly one process or is available.Hold and Wait
Processes currently holding resources granted earlier can request new resources.No Pre-emption
Resources previously granted cannot be forcibly taken away from a process. They must be explicitly released by the process holding them.Circular Wait
There must be a circular chain of two or more processes, each of which is waiting for a resource held by the next member of the chain.Handling Deadlock
The above points focus on preventing deadlocks. But what to do once a deadlock has occurred. The following three strategies can be used to remove deadlock after its occurrence.
Pre-emption: If a resource can be withdrawn from a process to be assigned to another process. Sometimes, it resolves the deadlock situation, however, it may cause problems in other cases.
Rollback: It indicates reverting the allocation of the resources of the running processes if deadlock occurs. In such scenarios, everything is rolled back to the last checkpoint (a safe point), and again restart allocation is different.
Kill one or more processes: This is the simplest way, but it works.
What is a Livelock?
There is a variant of deadlock called livelock. This is a situation in which two or more processes continuously change their state in response to changes in the other process(es) without doing any useful work.
Deadlock and this situation are similar in that no progress is achieved, but the latter differs in that neither process is stalled or waiting for anything. A human illustration of livelock might be two persons who come face to face in a hallway, one moving aside to let the other pass, but they end up swaying from side to side without moving forward since they always move in the same direction and at the same time.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.