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.
Let A and B be sets. Prove the following please show in as much detail as...
Let A and B be sets. Prove the following please show in as much detail as possible i. A ⊆ B is and only if A U B = B ii. A ⊆ B is and only if A ∩ B = A iii. A ⊆ B is and only if A \ B = empty set
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 complete the following program in c++: In this homework assignment you will modify the program...
please complete the following program in c++: In this homework assignment you will modify the program you have developed in Homework Assignment 1 by implementing the following: 1- Your program will ask the user to choose to either Compute and Display Surface Areas of Hemispheres and their Average (Choice 1) or to Compute and Display Volumes of Hemispheres and their Average (Choice 2). The program will only perform the chosen operation. (Hint: use a character variable to read the character...
Please Prove the following, be clear and percise. By removing sets with ever decreasing length, show...
Please Prove the following, be clear and percise. By removing sets with ever decreasing length, show that we can construct a "Cantor-like" set which has positive length. How large can we make the length of this set?
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT