🎓 BookMCQ
← Back to 5. Process Synchronization

📝 Peterson's Solution (51 MCQs)

📖 From Operating System • 5. Process Synchronization • 51 questions available

What is Peterson's Solution?

Definition:
Peterson's solution is a software-based algorithm for two-process mutual exclusion using shared variables turnturn and flag[2]flag[2] to enforce critical section entry without hardware support.

Example:
Process P0P_0 sets flag[0]=trueflag[0]=true and turn=1turn=1, then waits in while(flag[1]turn==1)while(flag[1] \land turn==1) before entering the critical section.

Reason:
It provides a provably correct software solution demonstrating that mutual exclusion, progress, and bounded waiting can be achieved purely through shared memory algorithms for N=2N=2.

17
Easy
21
Medium
13
Hard

📝 All Peterson's Solution MCQs

Q1. What is the fundamental nature of Peterson's solution?

A.A hardware-based solution for process synchronization.
B.A software-based solution for the critical-section problem. ✅
C.A compiler-level optimization for concurrent programming.
D.An operating system scheduling algorithm.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Peterson's solution is a classic software-based algorithm designed to solve the critical-section problem. It uses shared memory variables to coordinate access between two processes, demonstrating the principles of mutual exclusion, progress, and bounded waiting.

Q2. Peterson's solution is restricted to how many processes?

A.Unlimited number of processes.
B.Exactly two processes. ✅
C.Four processes.
D.Only the operating system kernel processes.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Peterson's solution is specifically designed for two processes, typically denoted as P0 and P1. This restriction is fundamental to the algorithm's operation, as it relies on a simple turn variable to arbitrate access between the pair.

Q3. What are the two shared data items used in Peterson's solution?

A.`int turn` and `boolean flag[2]`. ✅
B.`int count` and `boolean lock`.
C.`int mutex` and `int semaphore`.
D.`boolean ready[2]` and `int priority`.
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: Peterson's solution relies on two shared variables: an integer `turn` to indicate which process is allowed to enter the critical section, and a boolean array `flag[2]` to indicate whether each process is ready to enter its critical section. These variables coordinate the protocol.

Q4. In Peterson's solution, what does the variable `turn == i` signify?

A.Process Pj is in its critical section.
B.Process Pi is not ready to enter the critical section.
C.Process Pi is allowed to execute in its critical section. ✅
D.The critical section is empty.
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: When `turn == i`, it means that process Pi has the right to enter its critical section. This variable is used as a tie-breaker to resolve conflicts when both processes want to enter simultaneously, ensuring only one proceeds.

Q5. What does the `flag[i] = true` assignment in Peterson's solution indicate?

A.Process Pi is not interested in entering the critical section.
B.Process Pi is ready to enter its critical section. ✅
C.Process Pi has completed its critical section.
D.Process Pi is about to terminate.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Setting `flag[i] = true` signals that process Pi is ready and willing to enter its critical section. This is a key step in the entry section, as it communicates intent to the other process, which is crucial for implementing mutual exclusion.

Q6. What is the purpose of the `while (flag[j] && turn == j)` loop in Peterson's solution?

A.To ensure that both processes enter the critical section simultaneously.
B.To wait until the other process is ready and it is its turn. ✅
C.To indicate that the process is in its remainder section.
D.To reset the flags after exiting the critical section.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The while loop is the waiting mechanism. A process will stay in this loop if the other process is ready to enter (`flag[j] == true`) and it is currently the other process's turn (`turn == j`). Once one of these conditions becomes false, the process can proceed into its critical section.

Q7. According to the proof of Peterson's solution, what condition must be true for process Pi to enter its critical section?

A.`flag[j] == true` and `turn == i`.
B.`flag[j] == false` or `turn == i`. ✅
C.`flag[i] == true` and `turn == j`.
D.`flag[j] == true` or `turn == j`.
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: A process Pi can enter its critical section only if either the other process is not ready (`flag[j] == false`) or if it is Pi's turn (`turn == i`). This ensures mutual exclusion, as both processes cannot have this condition true at the same time.

Q8. What happens if both processes in Peterson's solution set `turn` to the other process's ID at approximately the same time?

A.Both processes enter the critical section simultaneously causing an error.
B.Both processes are stuck forever in their while loops.
C.The final value of `turn` determines which process enters the critical section first. ✅
D.The algorithm fails and a deadlock occurs.
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: If both processes try to set `turn` concurrently, one assignment will be overwritten by the other. The final value of `turn` is what matters. It acts as a deterministic tie-breaker, ensuring that only the process whose ID matches `turn` can proceed, thereby preserving mutual exclusion.

Q9. Which of the following is a limitation of Peterson's solution?

A.It requires a large amount of memory.
B.It only works for exactly two processes. ✅
C.It is a hardware-dependent solution.
D.It does not guarantee bounded waiting.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The most significant limitation of Peterson's solution is its restriction to only two processes. It is not designed for n-process mutual exclusion. This is a fundamental constraint of the algorithm, making it less scalable for general-purpose systems.

Q10. Why is Peterson's solution important despite its limitations?

A.It is the only solution that works on all hardware architectures.
B.It provides a clear algorithmic description and illustrates complexities of software synchronization. ✅
C.It is the most efficient solution for modern multiprocessor systems.
D.It does not require any shared memory.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Peterson's solution is important for educational and conceptual reasons. It provides a clear, elegant example of how software can solve the critical-section problem, helping to illustrate the challenges of mutual exclusion, progress, and bounded waiting. Its simplicity makes it a classic teaching tool.

Q11. What does `flag[j]` being `false` indicate in Peterson's solution?

A.Process Pi is in its critical section.
B.Process Pj is in its critical section.
C.Process Pj is not ready or not interested in entering its critical section. ✅
D.The variable `turn` is invalid.
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: If `flag[j]` is `false`, it indicates that process Pj is not currently ready to enter its critical section. This means process Pi does not have to wait for Pj and can proceed into its own critical section, assuming the `turn` condition is also met.

Q12. In Peterson's solution, what is the role of the `flag` array?

A.To indicate the process's priority.
B.To indicate if a process is ready to enter its critical section. ✅
C.To store the process ID.
D.To count the number of processes in the system.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The `flag` array is used to signal intent. `flag[i] = true` means process Pi is ready to enter its critical section. This is a necessary condition for the other process to determine if it needs to wait or can proceed.

Q13. Which requirement of the critical-section problem does Peterson's solution successfully satisfy?

A.Only Mutual Exclusion.
B.Only Progress and Bounded Waiting.
C.Mutual Exclusion, Progress, and Bounded Waiting. ✅
D.None of the three requirements.
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: Peterson's solution is a classic, elegant algorithm that correctly satisfies all three requirements of the critical-section problem: Mutual Exclusion, Progress, and Bounded Waiting. This is why it is a foundational example in concurrent programming, despite its limitations.

Q14. What is the result of a process Pi executing `turn = j` in the entry section?

A.It sets its own turn to enter the critical section.
B.It yields the critical section to the other process. ✅
C.It indicates that both processes are ready to enter.
D.It terminates the other process.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: By setting `turn = j`, process Pi is explicitly granting priority or preference to the other process. This ensures fairness and prevents a single process from monopolizing the critical section, as the process is signaling that it is willing to let the other go first.

Q15. Why might Peterson's solution not work correctly on modern computer architectures?

A.It uses too many memory variables.
B.It is not compatible with modern programming languages.
C.The algorithm relies on the atomicity of load and store instructions, which is not guaranteed on modern architectures. ✅
D.It requires a specific operating system.
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: Peterson's solution assumes that operations like loading and storing variables are atomic and occur in a predictable order. Modern architectures may reorder memory operations or have cache inconsistencies, leading to a situation where the algorithm's proof, based on sequential consistency, no longer holds, making it unreliable.

Q16. If process P0 sets `flag[0] = true` and `turn = 1`, and process P1 sets `flag[1] = true` and `turn = 0`, what ensures only one process enters the critical section?

A.The order of memory writes.
B.The while loop condition checking both `flag` and `turn`. ✅
C.The process's priority.
D.The operating system scheduler.
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The while loop condition `while (flag[j] && turn == j)` is the key. If both flags are true, the process that is not the current `turn` value will be stuck in its loop, while the other will proceed. The final value of `turn` ensures only one process exits the loop.

Q17. In the proof of bounded waiting for Peterson's solution, what is the maximum number of times process Pj can enter its critical section before Pi is allowed to enter?

A.Unlimited times.
B.At most one time. ✅
C.Exactly two times.
D.It depends on the scheduling algorithm.
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Bounded waiting is guaranteed because Pi sets `turn = j`. If Pj tries to enter again, it will set `turn = i`, allowing Pi to enter. This means after Pi's request, Pj can enter at most once before Pi is allowed to proceed, satisfying the bounded waiting requirement.

Q18. What is the purpose of the `remainder section` in Peterson's solution?

A.To handle the exit protocol.
B.To execute the critical section.
C.To execute non-critical code after the critical section. ✅
D.To initialize the flags and turn variable.
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: The remainder section is executed after the critical section and exit section. It contains the rest of the process's code that does not involve the shared resource, allowing the process to perform other computations while not in the critical section.

Q19. Which statement accurately describes the `turn` variable in Peterson's solution?

A.It is used as a flag to indicate readiness.
B.It is a shared integer used to determine which process's turn it is to enter the critical section. ✅
C.It is a boolean used to indicate if the critical section is empty.
D.It is a hardware register.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The `turn` variable is a shared integer that stores the ID of the process whose turn it is to enter the critical section. It is used as a simple and fair mechanism to decide which process gets access when both are ready.

Q20. Peterson's solution is a good example of:

A.A hardware-based mutual exclusion mechanism.
B.A software-based solution that satisfies all critical-section requirements. ✅
C.A solution that works well on multiprocessor systems.
D.A solution that requires no shared data.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Peterson's solution is a classic software-based algorithm that correctly addresses the critical-section problem. Its key achievement is satisfying Mutual Exclusion, Progress, and Bounded Waiting using only shared memory variables, making it a fundamental example in computer science.

Q21. If process Pi is in its critical section, what does the proof of mutual exclusion in Peterson's solution state about process Pj?

A.Pj must also be in its critical section.
B.Pj cannot be in its critical section. ✅
C.Pj is running in its remainder section.
D.Pj is in its entry section but is not executing.
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The mutual exclusion proof shows that if Pi is in its critical section, the condition for Pj to enter (`flag[i] == false` or `turn == j`) will be false, as `flag[i]` is true and `turn` is set to `j` (for Pj's entry). This prevents Pj from exiting its while loop, thus preserving mutual exclusion.

Q22. How does the `flag` array help satisfy the progress requirement in Peterson's solution?

A.By allowing a process to indicate it is not interested, thus allowing the other to proceed. ✅
B.By ensuring both processes enter simultaneously.
C.By preventing any process from ever entering.
D.By setting a process's priority to high.
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The `flag` array enables progress because a process will wait only if the other process has expressed interest (`flag[j] == true`). If the other process is not ready, the waiting process can enter, ensuring the system does not stall. This prevents indefinite postponement.

Q23. In the algorithm structure for process Pi, what is the correct sequence of actions?

A.flag[i] = true; turn = i; while (flag[j] && turn == j); critical section; flag[i] = false; remainder section.
B.flag[i] = false; turn = j; while (flag[j] && turn == i); critical section; flag[i] = true; remainder section.
C.flag[i] = false; turn = i; while (flag[j] && turn == j); critical section; flag[i] = true; remainder section.
D.flag[i] = true; turn = j; while (flag[j] && turn == j); critical section; flag[i] = false; remainder section. ✅
💡 Difficulty: easy | ✅ Correct: D

📖 Explanation: The correct sequence is: 1) Set `flag[i] = true` to indicate readiness. 2) Set `turn = j` to give the other process priority. 3) Wait in the while loop if the other is ready and it's their turn. 4) Execute the critical section. 5) Set `flag[i] = false` to indicate exit. This is the exact algorithm for Pi.

Q24. What is the significance of the statement `turn = j` in the algorithm for process Pi?

A.It prevents the other process from entering.
B.It ensures progress and bounded waiting. ✅
C.It causes a deadlock.
D.It is a redundant statement with no real effect.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The `turn = j` statement is crucial for ensuring progress and bounded waiting. By setting the turn to the other process, Pi demonstrates willingness to let Pj enter. This prevents any single process from hogging the critical section and ensures that the selection of the next process is fair, preventing starvation.

Q25. What is a key reason for studying Peterson's solution in operating systems courses?

A.It is the only practical solution for modern systems.
B.It is an efficient algorithm for many-core systems.
C.It provides a simple, elegant illustration of software synchronization. ✅
D.It is the standard used in all commercial operating systems.
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: Peterson's solution is a classic pedagogical tool. It provides an elegant and concise illustration of a software-based solution to the critical-section problem, demonstrating the core principles of mutual exclusion, progress, and bounded waiting in a way that is easy to understand and analyze.

Q26. What does the `while (flag[j] && turn == j)` condition check before a process can enter the critical section?

A.It checks if the other process is not ready and it's the process's turn.
B.It checks if the other process is ready and it's the other process's turn. ✅
C.It checks if the process is ready and it's its own turn.
D.It checks if the critical section is empty.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The while loop condition is the entry guard. It evaluates to `true` (and thus the process waits) only when the other process is ready (`flag[j] == true`) AND it is the other process's turn to enter (`turn == j`). If either is false, the process can proceed.

Q27. What is the primary proof mechanism used to show Peterson's solution ensures mutual exclusion?

A.The use of a hardware lock.
B.The invariant that `turn` can have only one value at a time. ✅
C.The operating system's scheduling policy.
D.The assumption that processes execute at the same speed.
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The mutual exclusion proof hinges on the `turn` variable. The proof argues that if both processes were in their critical sections, both `flag` entries would be true. However, because `turn` can only hold one value (0 or 1), one of the processes must have been the last to set `turn`, which would cause the other to be stuck in its while loop, proving mutual exclusion.

Q28. How does Peterson's solution handle the situation where process Pj completes its critical section and sets `flag[j] = false`?

A.Process Pi becomes permanently blocked.
B.Process Pi can then proceed past its while loop. ✅
C.Process Pi must wait for Pj to set `flag[j] = true` again.
D.The system enters a deadlock state.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: When Pj exits and sets `flag[j] = false`, the condition for Pi's while loop (`flag[j] && turn == j`) becomes false. This allows Pi to exit the loop and enter its critical section. The algorithm elegantly transfers access to the waiting process.

Q29. What does the variable `j` represent in the description of Peterson's solution for process Pi?

A.The ID of the other process. ✅
B.The ID of process Pi itself.
C.The priority of process Pi.
D.The number of processes in the system.
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: In the description, `j` is used to denote the other process. Since the algorithm is for two processes (P0 and P1), if `i` is the current process, `j` is calculated as `1 - i`. This notation simplifies the explanation of the algorithm by referring to the other participant.

Q30. Which of the following is NOT a characteristic of Peterson's solution?

A.It is a software-based solution.
B.It provides a solution for n processes. ✅
C.It uses a shared `turn` variable.
D.It demonstrates the complexities of software synchronization.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Peterson's solution is specifically designed for two processes. It is not an n-process solution. This is a key limitation and a defining characteristic of the algorithm, which is otherwise a classic and elegant software synchronization example.

Q31. If process P0 sets `flag[0] = true` and `turn = 1`, and P1 is in its remainder section, what will P0 do?

A.It will wait indefinitely.
B.It will enter its critical section. ✅
C.It will terminate.
D.It will set `flag[0] = false` and exit.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Since P1 is in its remainder section, `flag[1]` is `false`. The while loop condition for P0 (`flag[1] && turn == 1`) evaluates to `false` because `flag[1]` is `false`. Therefore, P0 will not wait and will proceed directly into its critical section.

Q32. What is the fundamental reason Peterson's solution might fail on modern processors?

A.Modern processors have less memory.
B.Modern processors may reorder memory operations, violating the assumptions of the algorithm. ✅
C.Modern processors are too fast for the algorithm.
D.Modern processors do not support integer variables.
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Peterson's solution assumes that memory operations like writes to `flag` and `turn` occur in the order they are programmed (sequential consistency). Modern CPUs often reorder memory operations for performance. This means a process might see the updated `turn` before the updated `flag`, causing the algorithm to fail as its proof is no longer valid.

Q33. In Peterson's solution, what happens after a process executes the `critical section`?

A.It immediately executes the `entry section` again.
B.It sets `flag[i] = false` to indicate it has left the critical section. ✅
C.It sets `turn = i` to indicate it is still interested.
D.It jumps to the `remainder section` without any further action.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: After a process finishes its critical section, it must execute the exit section, which in Peterson's solution is the statement `flag[i] = false`. This signals to the other process that it is no longer interested in the critical section, allowing the other process to potentially enter.

Q34. What is the role of the `flag` array in enforcing mutual exclusion?

A.It prevents both processes from setting their flags to true simultaneously.
B.It allows each process to indicate its intention to enter, which the other process checks before entering. ✅
C.It is used only for debugging purposes.
D.It stores the process IDs of all running processes.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The `flag` array is central to mutual exclusion. When a process wants to enter, it sets its `flag` to `true`. Before entering, it checks the other process's `flag`. If the other process's `flag` is `true`, it means the other process has also expressed interest, and the `turn` variable is used to resolve the conflict. This signaling mechanism prevents both from entering simultaneously.

Q35. The progress requirement in Peterson's solution is satisfied because:

A.A process will enter the critical section if the other process is not interested. ✅
B.The algorithm guarantees that both processes will enter simultaneously.
C.The operating system forcibly schedules the processes.
D.The `turn` variable is never changed.
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Progress is satisfied because a process is only delayed when the other process is both interested and has priority. If the other process is not interested, the waiting process can enter immediately. This ensures that the system cannot be indefinitely postponed and will make forward progress.

Q36. Which of the following best describes the educational value of Peterson's solution?

A.It is the most efficient algorithm for all operating systems.
B.It is a simple, clear example of solving the critical-section problem using only software. ✅
C.It is the only algorithm that works on multiprocessor systems.
D.It demonstrates the use of hardware instructions for synchronization.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Peterson's solution's primary value is educational. It provides an accessible and elegant demonstration of how software can solve the complex problem of process synchronization. It is an excellent starting point for understanding the principles of mutual exclusion, progress, and bounded waiting.

Q37. What is the maximum number of times a process can be bypassed in Peterson's solution?

A.Unlimited times.
B.At most once. ✅
C.At most twice.
D.It depends on the relative speeds of the processes.
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Peterson's solution ensures bounded waiting by guaranteeing that a process will be bypassed at most once. Since a process Pi sets `turn = j`, Pj will enter if it is ready. If Pj tries to enter again immediately after, it will set `turn = i`, allowing Pi to enter. This strict alternation ensures fairness.

Q38. What is the primary assumption about memory operations in the classic proof of Peterson's solution?

A.All memory operations are atomic and appear in program order. ✅
B.Memory operations are executed in a random order.
C.Memory operations are always cached.
D.Memory operations can be freely reordered by the compiler.
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: The proof of Peterson's solution relies on the assumption of sequential consistency, meaning memory operations are executed in the order they appear in the program code and are indivisible. This assumption is often violated in modern architectures, leading to the algorithm's practical failure.

Q39. If process P0 and P1 are both ready to enter their critical sections, what determines which one enters first in Peterson's solution?

A.The order in which they executed the `flag` assignment.
B.The final value of the `turn` variable. ✅
C.The priority of the processes.
D.The operating system scheduler.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: When both processes are ready, the `turn` variable is the deciding factor. The process whose ID matches the value of `turn` is the one that will be allowed to enter its critical section. The other process will be stuck in its while loop until the first process exits and resets its flag.

Q40. What action does a process take in the `exit section` of Peterson's solution?

A.It sets `flag[i] = true`.
B.It sets `turn = i`.
C.It sets `flag[i] = false`. ✅
D.It sets `turn = j`.
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: The exit section is defined by the statement `flag[i] = false`. This is the crucial step where a process signals that it has finished with the critical section, effectively releasing it so that the other process may enter. This is a simple but essential part of the algorithm.

Q41. How does Peterson's solution demonstrate the concept of 'bounded waiting'?

A.By allowing a process to enter the critical section immediately every time.
B.By ensuring a process will be bypassed by the other process at most once. ✅
C.By using a queue to manage waiting processes.
D.By setting a timer on how long a process can wait.
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Peterson's solution demonstrates bounded waiting by limiting the number of times a process can be bypassed. Since a process Pi sets `turn = j` when entering, it is effectively giving the other process priority. The other process can enter, but when it is done and tries to enter again, it must set `turn = i`, allowing Pi to proceed. This ensures no process waits forever.

Q42. Which of the following statements about the `turn` variable is true?

A.It is only used when both processes are trying to enter. ✅
B.It is used to signal a process is not interested.
C.It is set to `i` by process Pi.
D.It is an array of boolean values.
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The `turn` variable is specifically used as a tie-breaker when both processes are attempting to enter their critical sections. If only one process is interested, the `turn` variable is not needed, as the other process's `flag` will be `false`, and the interested process can enter immediately.

Q43. Why is Peterson's solution considered a classic in operating system design?

A.It is the most practical solution for modern systems.
B.It elegantly solves the critical-section problem for two processes using a simple, intuitive algorithm. ✅
C.It was the first solution to be invented.
D.It is the only solution that works on all hardware.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Peterson's solution is a classic because it provides a concise, elegant, and understandable software-based solution to the critical-section problem. Its beauty lies in its simplicity and the way it elegantly handles the complexities of concurrency using just two shared variables.

Q44. What is the effect of process Pi executing `turn = j` before checking `flag[j]`?

A.It ensures that if both processes are ready, Pj will have priority. ✅
B.It ensures that Pi will enter the critical section first.
C.It causes a deadlock.
D.It has no effect on the algorithm.
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: By setting `turn = j`, process Pi intentionally gives priority to the other process (Pj). This is a key part of the algorithm that ensures bounded waiting. If both processes are ready, the one that set `turn` last (the other process) will have priority, resolving the conflict.

Q45. How does Peterson's solution handle the situation where both processes have `flag` set to `true`?

A.It uses the `turn` variable to decide which process proceeds. ✅
B.It allows both processes to proceed, violating mutual exclusion.
C.It causes both processes to wait forever in a deadlock.
D.It randomly selects a process to proceed.
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: When both `flag` values are `true`, both processes are interested. The algorithm then relies on the `turn` variable as a deterministic tie-breaker. The process whose ID matches the value of `turn` will be allowed to proceed, while the other will wait, thus ensuring mutual exclusion is maintained.

Q46. What does the assignment `turn = j` in process Pi's entry section imply about the algorithm's philosophy?

A.The algorithm favors the process that sets `turn` last. ✅
B.The algorithm favors process Pi.
C.The algorithm favors the process that sets `turn` first.
D.The algorithm allows both processes to enter simultaneously.
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: By setting `turn = j`, Pi is, in a sense, being generous and letting Pj go first. If Pj subsequently sets `turn = i`, then Pi will go first. Thus, the process that executes the `turn` assignment last (the one with the most recent write) will be the one that does not have priority and will wait, while the other proceeds. This is a crucial insight for the algorithm's fairness.

Q47. Why is it important to understand the limitations of Peterson's solution regarding modern architectures?

A.To avoid using it in production systems without understanding potential memory ordering issues. ✅
B.To appreciate that all software solutions are equally flawed.
C.To learn that hardware synchronization is always superior.
D.To understand that the critical-section problem is unsolvable.
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Understanding the limitations is crucial for applying the right tools in the right context. While Peterson's solution is a great pedagogical tool, its reliance on sequential consistency means it's not safe for use on modern architectures. This highlights the need for hardware-supported or language-level synchronization primitives in production code.

Q48. What is the role of the `while` loop in the entry section of Peterson's solution?

A.It is a simple delay loop to waste CPU time.
B.It is a busy-waiting loop that prevents a process from entering until conditions are met. ✅
C.It is used to reset the flags of the other process.
D.It is used to update the `turn` variable.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The `while` loop is a form of busy waiting. The process continuously checks the condition `(flag[j] && turn == j)`. As long as this condition is true, the process cannot enter. This is a simple but CPU-intensive way to implement a wait, which is a common characteristic of early software solutions.

Q49. If process Pi is in its critical section, and process Pj has executed `flag[j] = true` and `turn = i`, what is the state of process Pj?

A.It is executing in its critical section.
B.It is blocked in its while loop. ✅
C.It is in its remainder section.
D.It has completed execution.
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Pj has set its flag to true and is waiting. Since Pi is in the critical section, Pi's flag is true and `turn` is likely `j` (from when Pi entered). For Pj, its while loop condition `(flag[i] && turn == i)` will be true (because Pi is in its critical section and `turn` is `i`). Therefore, Pj will be stuck in its while loop, waiting for Pi to exit.

Q50. What will happen in Peterson's solution if process Pi never executes its `exit section` after entering the critical section?

A.The system will continue to run normally.
B.Process Pj will also be able to enter its critical section.
C.Process Pj will be blocked forever in its while loop, causing a deadlock-like situation. ✅
D.The `turn` variable will be automatically reset.
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: If Pi never exits, it will not reset its `flag[i]` to `false`. For Pj, its while loop condition `(flag[i] && turn == i)` will remain true indefinitely, as `flag[i]` is true and `turn` is set to `i`. This causes Pj to wait forever. While Peterson's solution itself is correct, it assumes processes execute their exit sections, otherwise progress is violated.

Q51. How does the use of a simple software algorithm like Peterson's solution illustrate the challenges of process synchronization?

A.It shows that synchronization is a trivial problem.
B.It highlights the importance of considering even seemingly simple operations like memory reads and writes. ✅
C.It proves that hardware solutions are unnecessary.
D.It demonstrates that synchronization is impossible to achieve.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Peterson's solution beautifully illustrates the non-trivial nature of synchronization. It shows that even with two simple shared variables, designing a correct algorithm is not obvious. The fact that a seemingly correct algorithm can fail on modern hardware due to subtle issues like memory reordering highlights the complexity of the problem.

🔗 Related Topics (MCQs)