Deadlock, Livelock and Starvation Real World Examples
Explain Like I’m Five Deadlock, Livelock and Starvation
👋🏼 Hi, this is Antonio from The Developer Elevator! This newsletter is my attempt to write content the way I've always wanted to read them. I write about software architecture, software engineering and career advice in 5 minutes’ reading or less.
Today I’m explaining deadlock, livelock and starvation concepts using real world analogies so that you can grasp better what each of them is. You will be able to differentiate them just by recalling these simple examples.
Enjoy the post! 🚀
In computer science the ability of a system to make progress is called Liveness.
Imagine you have a toy, a car 🚗 that you can control with a remote controller 🕹️. You can accelerate, brake, turn left or right. However, the toy’s batteries can run out and the car stops moving. So while you play with your toy you constantly and unconsciously check that the toy is “alive”, whether it responds to your commands or not.
Liveness in computer science is critical, especially in concurrent systems, where multiple processes or nodes may be working and synchronizing together to accomplish a task.
A liveness property states that “something good will eventually occur”.
There are three specific issues that can affect the liveness of an application: deadlocks, livelocks and starvations.
DEADLOCK
I know you have seen this scene quite a few times.
Imagine two kids 👦🏻👧🏼 playing in a room. Suddenly they both want each other’s toy 🧸 to play with but one will not give up the toy until the other will do the same, however the other is thinking the same thing. Both kids get stuck, unable to play with any toy.
You are experiencing a deadlock.
A deadlock is a state in which each member of a group waits for another member, including itself, to take action (more commonly releasing a resource).
The system cannot make progress and the threads will potentially wait forever.
LIVELOCK
I’m pretty sure this has happened to you at least once.
Imagine you are walking 🚶🏻♂️in a corridor and in front of you there’s another person walking 🚶🏼♀️in your same direction.
At some point you meet one in front of the other and you both try to get out of each other’s way. Then one steps to the left and the other steps to the right and they are again in each other’s way, and again one steps to the right and the other to the left and the situation is exactly the same.
You are experiencing a livelock.
A livelock is similar to a deadlock, except that the states of the processes involved in the livelock constantly change with regard to one another, none progressing.
Livelock usually happens when there are some steps to mitigate a deadlock and they cause this perpetual corrective action which doesn’t allow the system making progress.
STARVATION
Imagine you have bought an economy class ticket for a flight ✈️ . Once you get to the airport you notice that there’s only a single check-in counter and two queues, one for business class and one for economy class.
As you may know the business class has the priority over the economy class.
However there is a business convention period and the business queue is always full. The economy queue doesn’t move at all and you will miss the plane as you cannot access the check-in counter.
You are experiencing a starvation.
A starvation generally occurs as a result of a deadlock, livelock, or caused by a greedy process.
A process which requires to complete a task that is unable to gain regular access to the shared resources.
📣 In case you have any topics you would like to read in the Explain Like I’m Five list fill in this form. I’ll take a look at your requests and in case I have knowledge about such topic I’ll cover it in an ELI5 future post!
Thanks for reading,
👍🏼 Share it!
Sharing is the most effective and better way to help and support The Developer Elevator. Whether you enjoyed it or believe that someone you know might, don't hesitate to share it.
🏅 Better yet - Subscribe!
Better than sharing you can subscribe for free if you haven’t! Or subscribe yours friends!