Operating System - Livelock



Livelock is a less common but a similar concept to deadlock. Read this chapter to understand what livelock is, how it occurs, its effects, and how it differs from deadlock. The following topics will be covered in this chapter −

What is Livelock?

Livelock is a situation that occurs when two or more processes continuously change their states in response to each other without making any progress. Meaning, the processes are active and consuming CPU cycles, but they are not able to complete their tasks. This happens when processes are designed to avoid deadlock by not blocking each other, but end up interfering with each other instead.

Here we have listed some of the most important characteristics of a livelock

  • In a livelock, the processes are not blocked completely. Instead, they are running and changing states continuously.
  • Livelock can lead to high CPU utilization.
  • The processes often keep executing by retrying the same operation repeatedly.

How Livelock Occurs

Livelock typically occurs when we try to implement deadlock avoidance mechanisms. For example, most common deadlock avoidance techniques are,

  • Back off and retry later
  • Resource preemption
  • Non-blocking Synchronization techniques

When multiple processes use such techniques in a dumb way, they may end up in a situation where they keep interfering with each other without making any progress. This results in livelock.

Example of Livelock

Consider two processes P1 and P2 is sharing a resource R. To prevent deadlock, both processes are designed to follow a rule that is "if the resource is busy, back off and retry later". This is polite way of dealing with resource sharing. However, the following timeline shows how livelock can occur in this scenario −

P1: Try to access R
P2: Try to access R

P1 sees R is busy, backs off
P2 sees R is busy, backs off

P1: Try again
P2: Try again

This cycle continues indefinitely...

Here, both processes keep backing off and retrying to access the resource R. Similar to a situation where two people trying to pass each other in a narrow hallway, they both step aside to let the other pass. In some cases, the side they step into will be coincidentally the same side. Now both people are again blocking each other. Being polite, they both decide to step aside again and give way to the other person. But again, they both step into the same side.

This continues indefinitely without either person being able to pass. In the case of real humans, they would eventually communicate and fix the situation. But the processes in a computer system may not be designed to communicate effectively, leading to livelock.

Effects of Livelock

The effects of livelock in an operating system are −

  • High CPU Utilization − Even though there is no progress being made, the processes are still active and consuming CPU cycles.
  • Degraded System Performance − Dumb way of handling deadlock can lead to livelock, which can degrade the overall performance of the system.
  • Resource Wastage The processes − keep retrying the same operation, which can lead to wastage of system resources.

Deadlock vs Livelock

A deadlock is a situation where two or more processes are blocked forever, waiting for each other to release resources. A livelock is different from a deadlock. The following table highlights the key differences between a deadlock and a livelock −

Aspect Deadlock Livelock
Definition A situation where two or more processes are blocked forever, waiting for each other to release resources. A situation where processes continuously change states without making progress.
Cause Mutual resource holding and waiting. Improper resource management, excessive backoff mechanisms.
Process State Processes are blocked and not executing. Processes are actively changing states but not progressing.
Impact on CPU Low CPU utilization as processes are waiting. High CPU utilization as processes are active but not progressing.
How to Fix? Resource preemption, process termination, or rollback. Redesign resource management strategies
Real-world Example Alice holding a pencil and waiting for Bob's notebook, while Bob is holding the notebook and waiting for Alice's pencil. Two people trying to pass each other in a narrow hallway, both decide to step aside at the same time repeatedly.

Conclusion

A livelock is a situation similar to a deadlock, where processes are active but not making any progress. It often occurs when deadlock avoidance mechanisms are implemented improperly. A livelock can lead to high CPU utilization, degraded system performance, and resource wastage. It is important to design resource management techniques carefully to avoid both deadlock and livelock situations in operating systems.

Advertisements