Questions tagged [livelock]

29 questions
388
votes
7 answers

What's the difference between deadlock and livelock?

Can somebody please explain with examples (of code) what is the difference between deadlock and livelock?
macindows
  • 4,303
  • 4
  • 18
  • 9
172
votes
12 answers

Good example of livelock?

I understand what livelock is, but I was wondering if anyone had a good code-based example of it? And by code-based, I do not mean "two people trying to get past each other in a corridor". If I read that again, I'll lose my lunch.
Alex Miller
  • 69,183
  • 25
  • 122
  • 167
14
votes
1 answer

How to let NHibernate retry deadlocked transactions when using session per request?

What pattern/architecture do you use in a 3-tiered application using NHibernate that needs to support retries on transaction failures, when you are using the Session-Per-Request pattern? (as ISession becomes invalid after an exception, even if this…
Henrik
  • 9,714
  • 5
  • 53
  • 87
8
votes
2 answers

Java: two WAITING + one BLOCKED threads, notify() leads to a livelock, notifyAll() doesn't, why?

I was trying to implement something similar to Java's bounded BlockingQueue interface using Java synchronization "primitives" (synchronized, wait(), notify()) when I stumbled upon some behavior I don't understand. I create a queue capable of storing…
starikoff
  • 1,601
  • 19
  • 23
6
votes
1 answer

two processes may change the same Redis resource, using Watch. Should I be worried for livelock?

Processes A and B both operate on a Redis resource R. These processes may be executed in parallel, and I need both processes to be certain of the value of R at the moment they change it. I'm therefore using Redis transactions with the WATCH…
Geert-Jan
  • 18,623
  • 16
  • 75
  • 137
3
votes
1 answer

Why does the monitor solution to dining-philosopher have no deadlock but starvation?

From Operating System Concepts 5.8.2 Dining-Philosophers Solution Using Monitors Next, we illustrate monitor concepts by presenting a deadlock-free solution to the dining-philosophers problem. This solution imposes the restriction that a…
Tim
  • 1
  • 141
  • 372
  • 590
3
votes
1 answer

Live Lock in ConcurrentHashMap

I hit live lock condition in concurrent hashmap #computeIfAbsent when function used for computation invokes #computeIfAbsent on the same map. Conceptually call invocation look like following final Map map = new…
3
votes
4 answers

Java Thread Live Lock

I have an interesting problem related to Java thread live lock. Here it goes. There are four global locks - L1,L2,L3,L4 There are four threads - T1, T2, T3, T4 T1 requires locks L1,L2,L3 T2 requires locks L2 T3 required locks L3,L4 T4 requires locks…
Dibakar Sen
  • 41
  • 1
  • 4
2
votes
1 answer

Is there a safe way to call gettimeofday() from a Xenomai real time thread?

I'm running a Xenomai real time thread that sometimes needs to call gettimeofday(), in order to find out what the current time is according to ptpd. However, doing that appears to be unsafe: in particular, it occasionally puts the Xenomai thread…
Jeremy Friesner
  • 70,199
  • 15
  • 131
  • 234
2
votes
1 answer

Circular Buffer with Threads Consumer and Producer: it get stucks some executions

I'm developing a circular buffer with two Threads: Consumer and Producer. I'm using active waiting with Thread.yield. I know that it is possible to do that with semaphores, but I wanted the buffer without semaphores. Both have a shared variable:…
Shondeslitch
  • 1,049
  • 1
  • 13
  • 26
2
votes
0 answers

How do I lock multiple mutexes in C (pthreads) and avoid the danger of deadlocks/livelocks?

Suppose you have a piece of code that is run by multiple threads. Now further suppose that each of these threads wants to lock the same set of mutexes, say 5, but not in a specific order: Thread 1: mutex1, mutex2, mutex3, mutex4, mutex5 Thread 1:…
Bastian
  • 4,638
  • 6
  • 36
  • 55
2
votes
6 answers

Is the C# "lock" construct rendered obsolete by Interlocked.CompareExchange?

Summary: It seems to me that: wrapping fields representing a logical state into a single immutable consumable object updating the object's authoritative reference with a call to Interlocked.CompareExchange and handling update failures…
Triynko
  • 18,766
  • 21
  • 107
  • 173
2
votes
4 answers

Java:Can reading from a HashMap change its state?

Concurrent updates to non-synchronized HashMap can obviously cause a livelock or other data corruptions; to avoid this, one should use the concurrent version or implement a synchronization mechanism. Can concurrent calls to HashMap.get() change the…
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
1
vote
1 answer

In Paxos, assume that acceptors do not change their vote, can it reach a livelock?

So, I’m studying Paxos and the Professor made this question: Assume that acceptors do not change their vote. In other words, if they vote for value v in round i, they will not send learn messages with value different from v in larger rounds. Show…
eddie
  • 45
  • 1
  • 4
1
vote
4 answers

Livelock or a Deadlock?

I'm preparing for Java SE 7 Programmer II exam. In one of the mock exams there was an exercise to name from what threading problem does the code suffer. This is the code: public class Test { public static void main(String[] args) { …
Goran
  • 21
  • 1
  • 6
1
2