Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A. If we changed the `<` in the 2nd `while()` loop to ``, what exactly would hap

ID: 3733273 • Letter: A

Question

A. If we changed the `<` in the 2nd `while()` loop to ``, what exactly would happen?

B. What would happen if we got rid of the chossing[] array?

C. What are the conditions that satisfy mutual exclusion, no starvation, and progress condition on the bakery algorithm?

while(true) {

choosing[i] = 1;

number[i] = 1 + max(number[1], …, number[n]);

number[n]);

choosing[i] = 0;

for (int j = 1; j <= n; j++) {

while (choosing[j] = 1) {}

while(number[j] != 0 and (number[j],j) < (number[i], i)) {}

}

critical section

number[i] = 0;

}

  

Explanation / Answer

1.

There will be no problem even if you replace < in second while loop with <= because we are replacing number[i]= 1+max(number[1]...number[n]) . We are adding 1 to the max number and replacing with numner[i]. Let assume max is 10 then we are storing 11 in number[i]. So either if we write 10< 11 or 10<=11 there will be no problem.

2.

If we do not use choosing array it will reduce cpu efficiency. Because even a process do not want to execute its critical section it will not let other process to use incase if it need.

Assume process i wants to use critical section but number[i]<number[j] so its processor j turn to use Critical section but if process j do not want to execute critical section still it will not let process i to use critical section

3. To satisfy mutual exclusion the necessary condition is ::

(number[j],j)<=(number[i],i) and (number[i],i)<=(number[j],j)

means (number[i],i)==(number[j],j) which is not possible science i and j are 2 different processes.

There is no starvation. To enter into the critical section (number[i],i)>=(number[j],j) means if process i wants to enter into critical section its number[i] should be greater than or equal to remaining all. Now to lets understand the senario of Starvation lets assume a process j with least number[j] wants to enter into critical section but it can not enter into critical section untill all other processes which number value is greater than number[i]. Science we have only finite processes after some point of time all other process complete their critical section and leave. Now to stop process j a process with greate than j should come which contradicts the condition (number[i],i)>=(number[j],j).

so there is no starvation.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote