Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 threadId =

new ThreadLocal() {@Override protected Integer initialValue() {

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Management Systems

Authors: Patricia Ward, George A Dafoulas

1st Edition

1844804526, 978-1844804528

More Books

Students also viewed these Databases questions