Complete the code to declare the flag array used in Peterson's solution.
boolean flag[2] = { [1], [1] };
The flag array is initialized to false for both processes, indicating neither wants to enter the critical section initially.
Complete the code to assign the turn variable in Peterson's solution.
turn = [1];The turn variable is assigned the other process's ID to give it priority in entering the critical section.
Fix the error in the waiting condition of Peterson's solution.
while (flag[[1]] && turn == [1]) { /* wait */ }
The waiting condition checks if the other process (j) wants to enter and if it's that process's turn.
Fill both blanks to correctly set flags and turn in Peterson's solution for process i.
flag[[1]] = true; turn = [2];
Process i sets its flag to true indicating it wants to enter, and sets turn to j to give priority to the other process.
Fill all three blanks to complete the exit section of Peterson's solution for process i.
flag[[1]] = [2]; // Process [3] exits critical section
Process i sets its flag to false to indicate it no longer wants to enter the critical section and exits.