What is the main goal of Peterson's solution in operating systems?
Think about what problem arises when two processes try to use the same resource at the same time.
Peterson's solution is a classic algorithm designed to ensure that two processes do not enter their critical sections simultaneously, thus achieving mutual exclusion.
Which two shared variables are used in Peterson's solution to coordinate access between two processes?
One variable indicates if a process wants to enter the critical section, and the other decides whose turn it is.
Peterson's solution uses a boolean array "flag[]" where each process sets its intent to enter the critical section, and a "turn" variable to decide which process gets priority.
Does Peterson's solution allow deadlock to occur? Why or why not?
Consider how the "turn" variable helps break ties when both processes want to enter.
Peterson's solution prevents deadlock by using the "turn" variable to give priority to one process, ensuring that if both want to enter, one will proceed while the other waits.
Compared to hardware-based locking mechanisms like test-and-set, what is a limitation of Peterson's solution?
Think about the number of processes and hardware requirements.
Peterson's solution is designed for exactly two processes and assumes sequential consistency in memory operations, which may not hold on modern hardware without additional memory barriers.
Despite its correctness, why is Peterson's solution rarely used in real-world operating systems today?
Consider how modern CPU architectures handle memory operations.
Modern CPUs often reorder memory operations for performance, which can break the assumptions Peterson's solution relies on unless special memory barriers are used, making it impractical for real systems.