Previous | Next --- Slide 9 of 66
Back to Lecture Thumbnails
kcoran

Is there a common code pattern to reason about livelock. I understand that we could create a situation where no one can get the shared resource each thread would spin on someone else and try again, but what pattern would guarantee this?

student1

^^+1. Meanwhile, is there a real-world example of a code snippet that leads to livelock? In general, it feels like livelock is even worse than deadlock as it is doing bunch of meaningless work but still stuck at the same situation as deadlock.

yt1118

I think thrashing is an example of livelock: https://en.wikipedia.org/wiki/Thrashing_(computer_science).

lee

The difference between livelock and deadlock is that in deadlock, the cars (or threads, or whatever's doing work) are stuck and unable to do anything because the others are holding the resources it needs to move on, while in livelock, the threads are still stuck, but they can move and keep doing stuff. Can deadlock ever happen inside livelock, or is it no longer deadlock because the cars still have the "back up" option?

pranil

There could be an interesting case where some threads are stuck in a deadlock (waiting for some other thread(s) to release a shared lock) and at the same time, some threads could be stuck in a livelock (for example, continuously spinning over a 'flag' variable)

sareyan

Another example I've heard described as livelock is if there are too many tasks to schedule and each task has a timeout window. Once the processor gets overloaded and a backlog forms, things can only get worse if the it can't clear out the backlog. It ends up performing a bunch of tasks that have already timed out when it would have been been to drop some tasks and move on to actually useful work.

tmdalsl

Can we assume livelock is just a subset of deadlock or is it better to think of them as 2 different concepts? Was wondering because we know there is no productive work that can continue between the threads in a livelock, just like deadlock.

jagriti

@tmdalsi - I tried looking this up - and since livelock is a special case of resource starvation, I feel we cannot really consider it a subset of deadlock and it's perhaps best to think of them as 2 different concepts maybe. (Because during a livelock - the threads are not blocked - they are simply too busy responding to each other to resume work)

Please log in to leave a comment.