Questions tagged [livelock]

28 questions
342
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
  • 3,813
  • 4
  • 15
  • 9
150
votes
11 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
  • 65,227
  • 26
  • 112
  • 160
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,303
  • 4
  • 49
  • 83
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,329
  • 14
  • 21
5
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
  • 16,760
  • 10
  • 68
  • 121
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
  • 122
  • 314
  • 481
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
  • 31
  • 1
  • 4
3
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
  • 107,447
  • 124
  • 346
  • 512
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
  • 57,675
  • 12
  • 103
  • 196
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,011
  • 1
  • 12
  • 25
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,248
  • 5
  • 34
  • 53
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
  • 17,370
  • 20
  • 92
  • 154
1
vote
0 answers

Java Threads - How to Detect if there is a Livelock

Good example of livelock? gives and excellent example of livelock, which occurs when writing fancy code to avoid deadlock situation. Thread acquires lock A, then tries to acquire lock B. If lock B is not free, it frees lock A, then after random…
Apurva Singh
  • 3,718
  • 3
  • 24
  • 35
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