what threading problem does the program suffer?

Given:

From what threading problem does the program suffer?

Given:

From what threading problem does the program suffer?

A.
deadlock

B.
livelock

C.
starvation

D.
race condition

Explanation:

A thread often acts in response to the action of another thread. If the other thread’s action is also a
response tothe action of another thread, then livelock may result. As with deadlock, livelocked

threads are unable to makefurther progress.
However, the threads are not blocked — they are simply too busy responding to each other to
resume work.
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. Seeing that they are still
blocking eachother, Alphone moves to his right, while Gaston moves to his left. They’restill
blocking each other, so.



Leave a Reply 7

Your email address will not be published. Required fields are marked *


Tim

Tim

I would vote for A.

l0c

l0c

Indeed it’s A.

A livelock is something that is very different from what is shown here.

Humberto Bañuelos Flores

Humberto Bañuelos Flores

/**
*
* @author Humberto
*/
class Counter extends Thread {
int i = 10;
public synchronized void display (Counter obj) {
try {
Thread.sleep(5);
obj.increment(this);
System.out.println(i);
}
catch (InterruptedException ex) { }
}
public synchronized void increment (Counter obj) {
i++;
}
}

public class Test {
public static void main(String[] args) {
final Counter obj1 = new Counter();
final Counter obj2 = new Counter();
new Thread(new Runnable() {
public void run() {
obj1.display(obj2);
}
}).start();
new Thread(new Runnable() {
public void run() {
obj2.display(obj1);
}
}).start();
}
}

peter

peter

The threads should be still running in livelock. In this case, both threads are waiting each other to proceed. Thus, it should be deadlock

Babak

Babak

These threads have lock in different objects so Deadlock should not happen.
only B is correct.

gelete

gelete

A

https://docs.oracle.com/javase/tutorial/essential/concurrency/deadlock.html

Deadlock describes a situation where two or more threads are blocked forever, waiting for each other.

public static void main(String[] args) {
final Friend alphonse =
new Friend(“Alphonse”);
final Friend gaston =
new Friend(“Gaston”);
new Thread(new Runnable() {
public void run() { alphonse.bow(gaston); }
}).start();
new Thread(new Runnable() {
public void run() { gaston.bow(alphonse); }
}).start();
}