0
0
Operating Systemsknowledge~20 mins

Peterson's solution in Operating Systems - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Peterson's Solution Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding the purpose of Peterson's solution

What is the main goal of Peterson's solution in operating systems?

ATo ensure mutual exclusion between two processes accessing a shared resource
BTo increase the speed of process execution by parallelizing tasks
CTo allocate memory dynamically to processes
DTo schedule processes based on priority levels
Attempts:
2 left
💡 Hint

Think about what problem arises when two processes try to use the same resource at the same time.

📋 Factual
intermediate
2:00remaining
Key variables in Peterson's solution

Which two shared variables are used in Peterson's solution to coordinate access between two processes?

A"semaphore" and "mutex"
B"priority" variable and "state" array
C"lock" variable and "counter" variable
D"flag[]" array and "turn" variable
Attempts:
2 left
💡 Hint

One variable indicates if a process wants to enter the critical section, and the other decides whose turn it is.

🔍 Analysis
advanced
2:00remaining
Analyzing Peterson's solution for deadlock

Does Peterson's solution allow deadlock to occur? Why or why not?

ANo, because it uses semaphores to prevent deadlock
BYes, because both processes can wait indefinitely if they set their flags simultaneously
CNo, because the "turn" variable ensures that one process will always proceed if both want to enter the critical section
DYes, because it does not handle process priorities
Attempts:
2 left
💡 Hint

Consider how the "turn" variable helps break ties when both processes want to enter.

Comparison
advanced
2:00remaining
Peterson's solution vs. hardware-based locking

Compared to hardware-based locking mechanisms like test-and-set, what is a limitation of Peterson's solution?

AIt requires special CPU instructions to function
BIt only works correctly for two processes and relies on strict memory ordering
CIt can handle multiple processes without any modification
DIt guarantees fairness without any waiting
Attempts:
2 left
💡 Hint

Think about the number of processes and hardware requirements.

Reasoning
expert
2:00remaining
Why Peterson's solution is not widely used in modern systems

Despite its correctness, why is Peterson's solution rarely used in real-world operating systems today?

ABecause modern CPUs have relaxed memory models that can break its assumptions without explicit memory barriers
BBecause it causes deadlocks in multi-threaded environments
CBecause it requires too much memory to store flags for each process
DBecause it only works on single-core processors
Attempts:
2 left
💡 Hint

Consider how modern CPU architectures handle memory operations.