CS计算机代考程序代写 CS 340

CS 340
Lecturer: Simina Fluture
Example of a problem given during the Midterm of a previous semester. Consider the following code for two concurrent processes:
Process 0
while (true){
Flag[0] , Flag[1] = False;
Turn = 0
process 1 while(true) {
L1: flag[0] = true; L1: while (flag[1] ) {
if (turn == 0) { flag [0] = False; }
while (turn ==1) go to L1;
}} CS
Turn = 1;
Flag[0] = False; remainder section;
Turn = 0;
Flag[1] = False;
remainder section; }}
1) Discuss if the condition of No Starvation is satisfied. (if yes, explain why, if no, explain why not – give the execution sequence)
2) Discuss if the Mutual Exclusion Condition is satisfied. (if yes explain why, if no, explain why not – give the execution sequence)
flag[1]= true;
while (flag[0] ) {
if (turn = = 1) { flag[1] = False; }
while (turn == 0) go to L1;
CS