Question
Suppose we redefine in the Bakery algorithm as below. (label [i],i) < < (label[j],j) If and only if label [i] < label [j] What would
Suppose we redefine in the Bakery algorithm as below.
(label [i],i) << (label[j],j) If and only if label [i] < label [j]
What would be the impact on the algorithm? Which of the lemmas 2.6.1, 2.6.2, and 2.6.3 will still be correct? (Or more precisely, which of them wnill continue to be lemmas?) If any of them continues to be a lemma, clearly justify your answer. For ones that are not lemmas anymore, explain with a counterexample.
import java.util.concurrent.atomic.AtomicInteger;
public class Bouncer extends Thread {
public static final int DOWN = 0;
public static final int RIGHT = 1;
public static final int STOP = 2;
private boolean gotRight = false;
private int last = -1;
public int visit() {int i = ThreadId.get(); last = i;if (gotRight) {
return RIGHT; }
gotRight = true;
AB
if (last == i) {return STOP;
} else {return DOWN;
} }
public void run() { System.out.println(visit());
}public static void main(String[] args) {
Bouncer bouncer = new Bouncer();int n = 15;Thread[] threads = new Thread[n];for (int index = 0; index < threads.length; index++) {
threads[index] = new Thread(bouncer); }
for (int index = 0; index < threads.length; index++) { threads[index].start();
} }
}class ThreadId {
private static final AtomicInteger nextId = new AtomicInteger(0); private static final ThreadLocal
new ThreadLocal
return nextId.getAndIncrement(); }
};public static int get() {
return threadId.get(); }
} }
}
Figure 1. Bouncer
public unlock() {victim = ThreadID.get();
Figure 2. Change to unlock for LockTwo
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started