Search code examples
multithreadingdeadlockstarvationlivelock

Difference between starvation, livelock, deadlock


Is this table a correct way to summarize difference between starvation, livelock and deadlock?
Mainly I am asking about "thread is active", "how many threads", "nr of resources / locks" columns correctness

thread is active how many threads nr of resources / locks summary
starvation yes 1 1 the thread is preceded by other threads in accessing the resource/lock
livelock yes 2 2 scenario like in deadlock, but the threads are actively running and freeing resources and trying to allocate them in reverse order, but the blocking situation repeats, etc.
deadlock no 2 2 Two threads claim two resources/locks but in reverse order. They immediately block both resources/locks and thus block each other

Solution

  • Column "Thread is active". If we open Oracle docs, we'll see that in all the cases a thread "is unable to make progress". So it's rather optimistic to call the starvation or livelocked threads as active. It's better to say that the state is blocked in deadlock case, and is not blocked in starvation and livelock, but unable to make progress.
    Column "How many threads". Deadlock and Livelock can block not only the 2 threads, but 2 and more, because thare are cases when threads block each other not directly, but in a circle. Screenshot from this video.