0
0
Operating Systemsknowledge~10 mins

Peterson's solution in Operating Systems - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare the flag array used in Peterson's solution.

Operating Systems
boolean flag[2] = { [1], [1] };
Drag options to blanks, or click blank then click option'
Afalse
Btrue
Cnull
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting flags to true initially, which incorrectly indicates both processes want to enter.
Using 0 or null instead of boolean false.
2fill in blank
medium

Complete the code to assign the turn variable in Peterson's solution.

Operating Systems
turn = [1];
Drag options to blanks, or click blank then click option'
A0
Bother
C1
Dprocess_id
Attempts:
3 left
💡 Hint
Common Mistakes
Setting turn to the current process's ID instead of the other process.
Using fixed values like 0 or 1 without considering the other process.
3fill in blank
hard

Fix the error in the waiting condition of Peterson's solution.

Operating Systems
while (flag[[1]] && turn == [1]) { /* wait */ }
Drag options to blanks, or click blank then click option'
Ai
B1
C0
Dj
Attempts:
3 left
💡 Hint
Common Mistakes
Using the current process's index instead of the other process's index.
Confusing the turn variable with the flag array index.
4fill in blank
hard

Fill both blanks to correctly set flags and turn in Peterson's solution for process i.

Operating Systems
flag[[1]] = true;
turn = [2];
Drag options to blanks, or click blank then click option'
Ai
Bj
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Setting turn to the same process's ID.
Setting the wrong flag index.
5fill in blank
hard

Fill all three blanks to complete the exit section of Peterson's solution for process i.

Operating Systems
flag[[1]] = [2];
// Process [3] exits critical section
Drag options to blanks, or click blank then click option'
Ai
Bfalse
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Setting flag to true instead of false on exit.
Using the wrong process ID in the comment.