Seeing that they are still blocking each other, Alphone moves to his right, while Gaston moves to his left. Between each pair of philosophers is a single chopstick a philosopher needs two chopsticks to eat. Consider the 'dining philosophers' problem: n philosophers are sitting around a table, wanting to eat. This is comparable to two people attempting to pass each other in a corridor: Alphonse moves to his left to let Gaston pass, while Gaston moves to his right to let Alphonse pass. Deadlock occurs when a system is unable to make progress because threads are blocking each other. However, the threads are not blocked they are simply too busy responding to each other to resume work. Livelock happens when a request for an exclusive lock is continually denied due to multiple overlapping shared locks that keep interfering. As with deadlock, livelocked threads are unable to make further progress. If the other thread's action is also a response to the action of another thread, then livelock may result. LivelockĪ thread often acts in response to the action of another thread. If one thread invokes this method frequently, other threads that also need frequent synchronized access to the same object will often be blocked.
For example, suppose an object provides a synchronized method that often takes a long time to return. This happens when shared resources are made unavailable for long periods by "greedy" threads. Starvation describes a situation where a thread is unable to gain regular access to shared resources and is unable to make progress.
LIVELOCK VS DEADLOCK SOFTWARE
Starvation and livelock are much less common a problem than deadlock, but are still problems that every designer of concurrent software is likely to encounter.