If x is initialized to 0 and x must be loaded into a register before being incremented. What are all possible values for x after both processes have finished the for loop.Process A Process B for (i = 1; i <= 5; i++) for (i = 1; i <= 5; i++) x = x + 1; x = x + 1;
Answer the following questions and elaborate your findings:bool flag[2]; // global flags int turn; // global turn variable Process 0 Process 1 flag[0] = TRUE; flag[1] = TRUE; // I am interested while (turn != 0) { while (turn != 1) { // while it is not my turn while (flag[1]) while (flag[0]) // while you are interested ; ; // do nothing: busy waiting turn = 0; turn = 1; // you are not interested, it is my turn } } // critical section flag[0] = FALSE; flag[1] = FALSE; // I am done and not interested
Show step-by-step that this solution does not satisfy the mutual exclusion condition. Does this solution satisfy the progress and bounded waiting conditions?Process 0 Process 1 while (lock != 0) while (lock != 0) ; ; lock = 1; lock = 1; in critical section lock = 0; lock = 0;
Does this solution satisfy the mutual, progress and bounded waiting conditions?Process 0 Process 1 while (turn != 0) while (turn != 1) ; ; in critical section turn = 1; turn = 0;
Show step-by-step that this solution does not satisfy the mutual exclusion condition. Does this solution satisfy the progress and bounded waiting conditions?Process 0 Process 1 while (flag[1]) while (flag[0]) ; ; flag[0] = TRUE; flag[1] = TRUE; in critical section in critical section flag[0] = FALSE; flag[1] = FALSE;
Does this solution satisfy the progress and bounded waiting conditions? Does this solution satisfy the mutual exclusion condition?Process 0 Process 1 flag[0] = TRUE; flag[1] = TRUE; while (flag[1]) { while (flag[0]) { flag[0] = FALSE; flag[1] = FALSE; while (flag[1]) while (flag[0]) ; ; flag[0] = TRUE; flag[1] = TRUE; } } in critical section in critical section flag[0] = FALSE; flag[1] = FALSE;
Do the following problems:bool flag[2]; // global flags, initially FALSE int turn; // global turn variable, initially 0 or 1 Process 0 Process 1 flag[0] = TRUE; flag[1] = TRUE; // I am interested while (flag[1]) { while (flag[0]) { // wait as long as you are interested if (turn == 1) { if (turn == 0) { // if it is your turn ... flag[0] = FALSE; flag[1] = FALSE; // I am no more interested while (turn != 0) while (turn != 1) // wait for my turn ; ; flag[0] = TRUE; flag[1] = TRUE; // let me try again } } } } in critical section in critical section turn = 1; turn = 0; // it is your turn now flag[0] = FALSE; flag[1] = FALSE; // I am not interested
We do not collect your practice work; but, similar problems will appear in quizzes and exams in the future. Note that I will not make any announcement in class for these short quizzes. In other word, short quizzes may take place at any time as long as I see it is appropriate. |