What is Peterson's solution used for in operating systems?
Peterson's solution is a method to ensure mutual exclusion, allowing two processes to share a single-use resource without conflicts or interference.
Click to reveal answer
beginner
Which two key variables does Peterson's solution use to control access?
It uses a 'flag' array to indicate if a process wants to enter the critical section and a 'turn' variable to decide which process's turn it is to enter.
Click to reveal answer
intermediate
How does Peterson's solution prevent both processes from entering the critical section at the same time?
By setting its own flag to true and giving the turn to the other process, a process waits if the other wants to enter and it is the other’s turn, ensuring only one enters at a time.
Click to reveal answer
intermediate
What are the three main properties Peterson's solution guarantees?
Mutual exclusion (only one process in critical section), progress (no process waits forever if the critical section is free), and bounded waiting (each process gets a chance eventually).
Click to reveal answer
advanced
Why is Peterson's solution mostly of theoretical interest today?
Because it requires strict assumptions like sequential consistency of memory operations, which modern processors and compilers may not guarantee, making it less practical for real systems.
Click to reveal answer
What does the 'turn' variable in Peterson's solution represent?
AThe total number of processes waiting
BThe number of times a process has entered the critical section
CThe priority level of a process
DWhich process's turn it is to enter the critical section
✗ Incorrect
The 'turn' variable indicates which process is allowed to enter the critical section next.
How many processes can Peterson's solution handle simultaneously?
AAny number of processes
BOnly two processes
CExactly three processes
DOnly one process
✗ Incorrect
Peterson's solution is designed specifically for two processes.
Which property ensures that no process waits forever in Peterson's solution?
ABounded waiting
BProgress
CMutual exclusion
DDeadlock
✗ Incorrect
Bounded waiting guarantees that each process will eventually enter the critical section.
What happens if both processes set their flags to true and the turn variable is set to one process?
AThe process that set its flag first enters
BBoth processes enter simultaneously
CThe process whose turn it is enters the critical section
DNeither process enters
✗ Incorrect
The process whose turn it is allowed to enter the critical section proceeds, ensuring mutual exclusion.
Why might Peterson's solution fail on modern processors?
ABecause modern processors reorder instructions affecting memory consistency
BBecause it uses too much memory
CBecause it only works with three or more processes
DBecause it requires special hardware
✗ Incorrect
Modern processors may reorder instructions, breaking the assumptions Peterson's solution relies on.
Explain how Peterson's solution uses the 'flag' array and 'turn' variable to achieve mutual exclusion.
Think about how a process signals it wants to enter and how it respects the other process's turn.
You got /3 concepts.
Describe the main limitations of Peterson's solution in practical operating systems.
Consider hardware and system behavior differences from the original assumptions.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of Peterson's solution in operating systems?
easy
A. To prevent two processes from accessing a shared resource simultaneously
B. To increase the speed of process execution
C. To allocate memory to processes
D. To schedule processes based on priority
Solution
Step 1: Understand the problem Peterson's solution addresses
Peterson's solution is designed to handle the critical section problem where two processes must not access a shared resource at the same time.
Step 2: Identify the main goal of the solution
The main goal is to ensure mutual exclusion, preventing simultaneous access to shared resources.
Final Answer:
To prevent two processes from accessing a shared resource simultaneously -> Option A
Hint: Peterson's solution controls access to shared resources [OK]
Common Mistakes:
Confusing it with process scheduling
Thinking it manages memory allocation
Assuming it increases execution speed
2. Which of the following variables is NOT used in Peterson's solution?
easy
A. flag
B. turn
C. counter
D. process_id
Solution
Step 1: Recall the variables used in Peterson's solution
Peterson's solution uses two flags (one per process) and a turn variable to control access.
Step 2: Identify the variable not part of the solution
The variable 'counter' is not used in Peterson's solution; it is unrelated to mutual exclusion control.
Final Answer:
counter -> Option C
Quick Check:
Variables used = flag, turn; counter not used [OK]
Hint: Remember only flag and turn variables are used [OK]
Common Mistakes:
Assuming process_id is a variable in Peterson's solution
Confusing counter with flag
Thinking turn is a counter
3. Consider two processes P0 and P1 using Peterson's solution. If both set their flags to true and turn to 1, which process will enter the critical section first?
medium
A. P0
B. P1
C. Both enter simultaneously
D. Neither enters
Solution
Step 1: Analyze the turn variable's role
The turn variable indicates which process's turn it is to enter the critical section when both want access.
Step 2: Apply the given values
Both flags are true, meaning both want to enter. Since turn is set to 1, process P1 has priority to enter first.
Final Answer:
P1 -> Option B
Quick Check:
Turn = 1 means P1 enters first [OK]
Hint: Turn variable decides which process enters first [OK]
Common Mistakes:
Assuming both enter simultaneously
Ignoring the turn variable
Thinking the first flag set enters first
4. Identify the error in this Peterson's solution snippet for process P0: