You are on page 1of 4

Peterson

solution

Rajan Mabo Limbu


BCA, 4th Semester

1
Why Peterson solution ?

• For critical section problems


• This is a software mechanism
implemented at user mode.

2
Algorithm for Peterson solution

• For this algorithm ,we have two variables


i.e. interested & turn variable
• Initial state of interested variable is False &
that of turn variable is zero
• Since this algorithm is for solving CS
problem we have to go through entry &
exit section.
3
• Let’s take two processes p0 & p1.

# define N 2
# define TRUE 1
# define FALSE 0
int interested[N] = FALSE;
int turn;
For entry section

Entry section(process)
{ For two process
1. int other; synchronization
2. other = 1-process; //other=partner
3. interested[process]=TRUE;
4. turn = process
5. while(interested[other] = TRUE &&
turn = process )
}
If condition 5 satisfy, it enter CS

For exit section

Exit section( process)


{
6. interested[process] = FALSE; 4
}

You might also like