Question

In: Computer Science

Please prove the correctness of the following extended compare_and_wait program in terms of mutual exclusion, progress,...

Please prove the correctness of the following extended compare_and_wait program in terms of mutual exclusion, progress, and bounded waiting.

please show it in the in terms of mutual exclusion, progress, and bounded waiting.aspects thankyou

while (true) {
waiting[i] = true;
key = 1;
while (waiting[i] && key == 1)

key = compare_and_swap(&lock,0,1);

waiting[i] = false;

  

// critical section

j = (i + 1) % n;

while ((j != i) && !waiting[j])

j = (j + 1) % n;

if (j == i)

lock = 0;

else

waiting[j] = false;

  // remainder section

}

Solutions

Expert Solution

Mutual exclusion can be provided as follows --

A global variable (lock) is declared and initialized to 0. The first process that invoke compare_and_swap() will set lock to 1, it will then enter in critical section , because the original value of lock is equal to the expected value of 0.

subsequent calls to  compare_and_swap() will not succeed , because lock now is not equals to the expected value of 0. When a process exits critical section ,it sets lock back to 0, which allow other process to enter in critical section

hence it satisfies Mutual exclusion as well as progress is also satisfied as new process is entering in critical section

Bounded waiting is also satisfied as follows :-

  • when process leaves the critical section it scans the array waiting in cyclic ordering (i+1,i+2------------n-1,0,--------i-1)
  • It designates the first process in this ordering and this is the entry section (waiting[j]==true) as the next one to enter the critical section .
  • Any process waiting to enter its critical section will thus do so within ( n-1 ) turns.

Hence it has a finite waiting time

THANK YOU!!


Related Solutions

Write a program to simulate the Distributed Mutual Exclusion in ‘C’.
Write a program to simulate the Distributed Mutual Exclusion in ‘C’.
Modify the included program to implement the strict alternation solution to achieve mutual exclusion. It does...
Modify the included program to implement the strict alternation solution to achieve mutual exclusion. It does not matter whether Thread 0 goes first or Thread 1, but it is important that the thread strictly alternate. PROGRAM: #include <iostream> #include <pthread.h> #include <stdlib.h> int count; int turn = 0; // Shared variable used to implement strict alternation void* myFunction(void* arg) {    int actual_arg = *((int*) arg);       for(unsigned int i = 0; i < 10; ++i) {    //...
please match the following key terms with their examples.       -       A.   ...
please match the following key terms with their examples.       -       A.       B.       C.       D.       E.       F.    A construction worker building a house       -       A.       B.       C.       D.       E.       F.    The nail gun used by the construction worker       -       A.       B.       C.   ...
Let (xn) be a sequence with positive terms. (a) Prove the following: lim inf xn+1/ xn...
Let (xn) be a sequence with positive terms. (a) Prove the following: lim inf xn+1/ xn ≤ lim inf n√ xn ≤ lim sup n√xn ≤ lim sup xn+1/ xn . (b) Give example of (xn) where all above inequalities are strict. Hint; you may consider the following sequence xn = 2n if n even and xn = 1 if n odd.
This project involves writing a program to calculate the terms of the following sequence of numbers:...
This project involves writing a program to calculate the terms of the following sequence of numbers: 0 1 1 3 5 11 21 43 … where each term is twice the second previous term plus the previous term. The 0th term of the sequence is 0 and the 1st term of the sequence is 1. The example below shows how to calculate the next sequence term: Current sequence: 0 1 Calculate next term: 2 * 0 + 1 = 1...
Please use any of the methods to prove whether each of the following arguments is valid...
Please use any of the methods to prove whether each of the following arguments is valid or invalid. For each problem, please identify the method that you have decided to employ and make sure to show your work. 1. It is obvious that nuclear energy is needed. Nuclear energy is needed if and only if solar energy cannot be harnessed. And it is also true both that solar energy can be harnessed only if funds to do so are available,...
Please make the following changes to the following code: #This program takes in the first and...
Please make the following changes to the following code: #This program takes in the first and last name and creates a userID printing first letter of first name and first 7 characters of last name #by Abi Santo #9/20/20 def main(): print("This Program takes your first and last name and makes a User ID") f_name = str(input("Please enter your first name ")).lower() l_name = str(input("Enter your last name: ")).lower() userID = str(f_name[:1]+str(l_name[:7])) print(userID) main() Call the function createUserName(). This function...
Please provide a short definition of the following terms along with an example of each. a....
Please provide a short definition of the following terms along with an example of each. a. GAAP: b. P&L Statement c. EBITDA d. COGS
Please construct an essay that explains five of the following ideas or terms and the challenges...
Please construct an essay that explains five of the following ideas or terms and the challenges that they continue to present: Shadow banking system Enterprise risk management Change in mortgage markets Gap management Asymmetric information Macro-prudent supervision
Write an assembly language program that corresponds to the following C program ****Please give correct answer...
Write an assembly language program that corresponds to the following C program ****Please give correct answer using Pep/9 machine**** int num1; int num2; ;int main () { scanf("%d", &num1); num2 = -num1; printf("num1 = %d\n", num1); printf("num2 = %d\n", num2); return 0; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT