The definition provided by the Free On-Line Dictionary Of Computing [1] is
“Anomalous behavior due to unexpected critical dependence on the relative timing of events”.
Probably the best known result of a race condition is deadlock. A less well known problem is that of livelock.
www.cs-repository.info
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
www.cs-repository.info
www.cs-repository.info
John Eipe wrote:I'm trying to modify the above code(deadlock example) to simulate livelock. Are there methods to obtain and release locks on an object. (without using class ReentrantLock)?
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
www.cs-repository.info
John Eipe wrote:I conclude that: only ways to lock - unlock on objects is by using the Lock interface.
Here is example for LiveLock.
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
www.cs-repository.info
www.cs-repository.info
John Eipe wrote:Then the Livelock code I posted is a deadlock only, right?
If we use wait()/join()/sleep() what happens is blocking and when blocking comes into picture it's deadlock.
Your code is the right example. Thanks.
With a small change to the definition of Deadlock, all these situations could fall under it.
Stephan van Hulst wrote:
With a small change to the definition of Deadlock, all these situations could fall under it.
For instance, we could say that Deadlock is what happens when a program fails to make any progress because of the existence of multiple running threads that hold resources needed by other threads, be these resources processor time, I/O resources, or object locks.
Jim Akmer wrote:
2) Livelock is a form of liveness failure where a thread, although is not blocked, is impossible to make any actual progress because it keeps retrying an operation that can only fail.
Note: I know that a livelock isn't just a spinning wait deadlock -- I am just saying that the example provided is a spinning wait deadlock.
www.cs-repository.info
John Eipe wrote:
You seem to contradict. From your explanations it seems that livelock is indeed a spinning wait deadlock.
If it's different, could you post a example for livelock that will help me understand better. Thanks.
www.cs-repository.info
When many threads are trying to acquire or set many resources, be it synchronization locks, file locks, database locks, or even setting a state in a state machine, a deadlock is when there is a circular dependency when the threads are trying to set those resources, and hence, can't be resolved.
The techniques in preventing the deadlock are the same. The techniques in detecting (although not the tools) are the same.
So, a live lock is a deadlock, but it isn't block?
Is there really much of a difference between a thread spinning to wait for the lock, via trylock(), and the JVM putting putting the lock in a blocked state?
I don't see the point of making the distinction. In both cases, the techniques / designs to prevent the deadlock are the same. The techniques to recover from that condition are the same. etc.
I specifically said that the example was *not* an example of a livelock, but of a deadlock. ....If the definition of live lock was a spinning wait deadlock, then while the definition would not be vague, the distinction would be completely pointless.
Jim Akmer wrote:I have already given an example of livelock that has nothing to do with this i.e. packet collision in ethernet. Network protocols have build in mechanism to avoid this livelock
Jim Akmer wrote:Spinning wait deadlock? The example is trivial, but there is no deadlock. Both threads keep retrying an operation that can only fail. No thread is blocked. It is like the common example, of the 2 guys in the corridor that both make way for each other but in the same direction
Henry Wong wrote:
Jim Akmer wrote:I have already given an example of livelock that has nothing to do with this i.e. packet collision in ethernet. Network protocols have build in mechanism to avoid this livelock
And I actually *loved* the example.
This example is a case of a form of a partial resource starvation, an attempt to solve that resource starvation, that if not done right, aggravates the issue to a complete resource starvation. IOWs, the code that supposed to fixed the issues aggravates the issues.
This example is a case of a form of a partial resource starvation
IOWs, the code that supposed to fixed the issues aggravates the issues.
And the algorithm makes no attempt to solve the problem
In the case of "2 guys in the corridor", they are attempting to solve the problem. This is more like both guys trying to move forward and expecting the other to move out of the way
And I agree, the example is simple -- maybe too simple, because it is clearly a deadlock. If it is something else, I don't see it.
how vague the definition of livelock is
when talking to a client, I use specific terms that describes the problem... such as "nak storms", "crybaby receivers", etc... I have never ever used "livelock" in such discussions.
At this point, I think it is best to just agree to disagree -- as this debate seems to be going in circles. Or maybe into a live lock.
See ya later boys, I think I'm in love. Oh wait, she's just a tiny ad:
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
|