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

Question 1: Think about this general question: why does Eisenberg-McGuire as a s

ID: 3582757 • Letter: Q

Question

Question 1:
Think about this general question: why does Eisenberg-McGuire as a software solution to the n-process
critical sector problem require 2 levels of scanning, and 2 levels of activation (WANT_IN, IN_CS)? Hint:
this is a software solution and does not imply the use of an atomic test-and-set or compare_and_swap.
Answer each part of the specific question 1 that applies (a and b, or a and c).
The first while loop in Eisenberg-McGuire checks all processes’ flag[] from the one holding “turn” to
ourselves, stopping at each one that is not idle until it is idle, then proceeding.
a. Is it possible for two or more processes to go through this first loop and find all processes but
itself idle? Explain either way, not just yes or no.
b. If this is not possible, why does each process finding all others idle need the second loop, to
tentatively claim the CS, that is set its flag to IN_CS and then scan to see if any other process has
also asserted IN_CS? Why wouldn’t the process finding all but itself idle automatically have turn
set to it by the process exiting the CS? Why not just enter the CS if all other processes are idle?
c. If it is possible for 2 or more processes to find all but themselves idle, would they have to wait for
“turn” or could they try to enter the CS at the same time? Explain your conclusion. Hint: must a
process waiting for the CS have to get the “turn” or is there another condition in which it can
enter?

Explanation / Answer

This is a software solution, hence it is operating system

shared structures: enum xstates {idle, want_in, in_cs};

xflags[n] int turn;/*where turn can be initialized to any value between 0 and n-1*/

                do{

while (true){

flags[i] := want_in;

j= turn;

while (j != i) {

                                                if (flags[j] != ideal) {

                                             j := turn;

                                                else

                                              j := (j+1) mod n;

                                }

                                /* now tentatively claim the resource */

                                flags[i] := in_cs;

                            /* find the first active process besides ourselves, if any */

                                j:= 0;

                                while ((j < n) && ((j= i) || (flags[j] != in_cs))) {

                                                j := j+1;

                                }

                /* if there were no other active processes, AND if we have the turn

                   or else whoever has it is idle, then proceed. Otherwise, repeat

                   the whole sequence. */

        } until ((j>= n) && ((turn = i) || (flags[turn] = idle)));

        /* Start of CRITICAL SECTION */

       /* claim the turn and proceed */

                turn := i;

/* Critical Section Code of the Process */

/* End of CRITICAL SECTION */

/* find a process which is not IDLE *

/* (if there are no others, we will find ourselves) */

                j:= (turn+1) mod n;

                while (flags[j] = idle) {

                                j := (j+1) mod n;

                }

/* give the turn to someone that needs it, or keep it */

                turn := j;

/* we're finished now */

                flags[i] := idle;

                      /* Remainder Section */

         }while (true);

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