Implementation for Peterson’s Algorithm for three threads another version is below.  You can assume flag and victim are volatile in the Java sense suppose we have three threads using this newest version for locking.Java Programming

  1. I gave an incorrect implementation for Peterson’s Algorithm for three threads. Another version is below.  You can assume flag and victim are volatile (in the Java sense).   Suppose we have three threads using this newest version for locking.  Is this version safe (provides mutual exclusion) and deadlock-free?  

1       class Peterson implements Lock {

2       private boolean[] flag = new boolean [3];  // initially false

3       private int victim;

4       public void lock() {

5           int i = ThreadID.get();   // will = 0,1,or 2

6           int j = (i+1)%3;  int k = (i+2)%3;   // other two indices    

7           flag[i] = true;

8           victim = i;        

9           while ((flag[j] || flag[k]) && victim == i) { } // wait

10       }

11      public void unlock() {

12          int i = ThreadID.get();

13          flag[i] = false;

14       }

15  }



  1. (20 points) Concurrency Smith has finished CS470 and is now employed by an exciting startup company. Her first task is to architect the company’s new lead project – a recipe sharing app.  In this pandemic, recipes have become huge and the company expects this to be bigger than Pinterest supporting millions of people viewing new recipes every day.  Concurrency is concerned that the decisions she makes today will come back to haunt her after product launch.   In particular, she knows she needs to use replication to (1) provide fault tolerance and (2) to improve performance.   Help her make the following choices. 
    • Consistency Model: She is wondering whether to utilize Sequential Consistency or Eventual consistency. What are these models and what are the cost/benefits.  Thinking about how users might interact with such a system, geographic locations, availability, etc. – what is her best option?
    • Failure model: We discussed crash-stop, partition and byzantine.  After describing each mode, which do you think Concurrency’s product should tolerate and why?




Instructions Files

Java Programming Experts

Neno S.
Java Programming

60 Answers

Ray Bjork
Java Programming

90 Answers

View More Experts

The ready solutions purchased from Library are already used solutions. Please do not submit them directly as it may lead to plagiarism. Once paid, the solution file download link will be sent to your provided email. Please either use them for learning purpose or re-write them in your own language. In case if you haven't get the email, do let us know via chat support.

Get Free Quote!

264 Experts Online