Peterson’s Solution
Presented by Mustahsan Mehmood
Peterson’s Solution
A classical software based solution
May not work correctly on modern computer architecture
However, it provides a good algorithmic description
Address the requirements of Mutual Exclusion, Progress and Bounded Wait
❑ Restricted to Two Processes: Pi
and Pj
Shared Data Items
int turn
•• Indicates whose turn it is to
enter the critical section
boolean flag[2]
•• Indicate if a process is ready
to enter it’s critical section
Structure of process Pi
flag[ i ] = false;
flag [ i ] = true; // Ready to enter it’s critical section
turn = j; // Asking other process if it wants to enter it’s C.S
while ( flag[ j ] && turn == j );
do {
} while(true);
Critical Section
Remainder Section
Process Pi
Process Pj
flag[ i ] = false;
flag[ i ] = true;
turn = j;
while ( flag[ j ] && turn == j );
do {
} while(true);
Critical Section
Remainder Section
flag[ j ] = false;
flag[ j ] = true;
turn = i;
while ( flag[ i ] && turn == i );
do {
} while(true);
Critical Section
Remainder Section
Solution must satisfy following three requirements:
1. Mutual Exclusion: If process Pi is executing in its critical section,
then no other processes can be executing in their critical sections.
2. Progress: If no process is executing in its critical section and some
processes wish to enter their critical sections, then only those
processes that are not executing in their remainder sections can
participate in deciding which will enter its critical section next, and this
selection cannot be postponed indefinitely
3. Bounded Waiting: There exists a bound, or limit, 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.
THANK YOU

Peterson’s Solution.pdf by Mustehsan Mehmood

  • 1.
  • 2.
    Peterson’s Solution A classicalsoftware based solution May not work correctly on modern computer architecture However, it provides a good algorithmic description Address the requirements of Mutual Exclusion, Progress and Bounded Wait ❑ Restricted to Two Processes: Pi and Pj
  • 3.
    Shared Data Items intturn •• Indicates whose turn it is to enter the critical section boolean flag[2] •• Indicate if a process is ready to enter it’s critical section
  • 4.
    Structure of processPi flag[ i ] = false; flag [ i ] = true; // Ready to enter it’s critical section turn = j; // Asking other process if it wants to enter it’s C.S while ( flag[ j ] && turn == j ); do { } while(true); Critical Section Remainder Section
  • 5.
    Process Pi Process Pj flag[i ] = false; flag[ i ] = true; turn = j; while ( flag[ j ] && turn == j ); do { } while(true); Critical Section Remainder Section flag[ j ] = false; flag[ j ] = true; turn = i; while ( flag[ i ] && turn == i ); do { } while(true); Critical Section Remainder Section
  • 6.
    Solution must satisfyfollowing three requirements: 1. Mutual Exclusion: If process Pi is executing in its critical section, then no other processes can be executing in their critical sections. 2. Progress: If no process is executing in its critical section and some processes wish to enter their critical sections, then only those processes that are not executing in their remainder sections can participate in deciding which will enter its critical section next, and this selection cannot be postponed indefinitely 3. Bounded Waiting: There exists a bound, or limit, 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.
  • 7.