Motos, Aldrei Nicolas S.
05/27/22
BSCpE - 2A Sir. Louievic Sancon
What is Peterson’s Solution?
Peterson’s Solution is used to synchronize processes to share a single – use resource
without conflict, using only shared for communication. It was formulated by Gary L.
Peterson in 1981. While Peterson’s original formulation worked with only two processes,
the algorithm can be generalized for more than two. Peterson’s solution provides a good
algorithmic description of solving the critical section problem and illustrates some of the
complexities involved in designing software that addresses the requirement of mutual
exclusion, progress, and bounded waiting. Peterson’s solution is one of the most widely
used solutions to the critical section. It is a classical software – based solution.
Peterson’s algorithm uses two variables:
• Int turn: the process whose turn is to enter the critical section.
• Boolean flag: Value of true indicates that the process wants to enter the
critical section initialized to FALSE, initially no one is interested in entering
the critical section problem.
The Critical Section problem is used to design a protocol followed by a group of processes,
so that when one process has entered its critical section, no other process is allowed to
execute in its critical section.
The algorithm satisfies the three essential criteria to solve the critical section problem.
naming Mutual Exclusion, Progress, and Bounded waiting:
• Mutual Exclusion – a program object that prevents simultaneous access to a
shared resource. This concept is used in concurrent programming with a critical
section, a piece of code in which processes or threads access a shared resource
• Progress – is defined as the following: if no process is executing in its critical section
and some processes wisht to enter their critical sections, then only those processes
that are not executing in their remainder sections can participate in making the
decision as to which process will enter its critical section next. Note that for a
process or thread, the remainder sections are parts of the codes that are not
related to the critical section. This selection cannot be postponed indefinitely .
• Bounded Waiting – a bound must exist on the number of times that other
processes are allowed to enter their critical sections after a process has made a
request to enter its critical section and before that request is granted.
The structure of process Pi in Peterson’s solution. This solution is restricted to two
processes that alternate execution between their critical sections and remainder sections.
The processes are numbered P0 and P1. We use Pj for convenience to denote the other
process when Pi is present; that is, j equals 1 – I, Peterson’s solution requires the two
processes to share two data items.
Int turn;
Boolean flag [2];
The variable turn denotes whose turn it is to enter its critical section. I.e., if turn == I, then
process Pi is allowed to execute in its critical section. If a process is ready to enter its
critical section, the flag array is used to indicate that. For E. g., if flag[i] this value indicates
that Pi is ready to enter its critical section. With an explanation of these data structures
complete. We are now ready to describe the algorithm shown in above. To enter the
critical section, process pi first sets flag. To be true and then sets turn to the value j,
thereby asserting that if the other process wishes to enter the critical section, it can do
so. Turn will be set to both I and j at roughly the same time, if both processes try to enter
at the same time. Only one of these assignments will occur ultimately; the other will occur
but will be overwritten immediately. The final value of turn determines which of the two
processes is allowed to enter its critical section first. We now prove that this solution is
correct. We need to show that
• Mutual Exclusion is preserved.
• The progress requirement is satisfied.
• The bounded waiting requirement is met.
REFERENCES
Wikipedia contributors. (2022, March 22) Peterson's Algorithm.
https://en.wikipedia.org/wiki/Peterson%27s_algorithm
GeeksforGeeks. (2021, June 28) Peterson's Problem
https://www.tutorialspoint.com/peterson-s-problem
I2 Tutorials (2019) Peterson's Solution in Operating System.
https://www.i2tutorials.com/os-introduction/os-petersons-solution
TechoPedia (2019, June 4) What does mutual Exclusion (mutex) mean
https://www.techopedia.com/definition/25629/mutual-exclusion-
mutex#:~:text=A%20mutual%20exclusion%20(mutex)%20is,threads%20access%20a%20sha
red%20resource