Peterson's Solution for critical section problem

preview_player
Показать описание
#Peterson’sSolution #criticalsection #oslectures
Peterson’s Solution is a classical software based solution to the critical section problem.

In Peterson’s solution, we have two shared variables:

boolean flag[i] :Initialized to FALSE, initially no one is interested in entering the critical section
int turn : The process whose turn is to enter the critical section.
Peterson’s Solution preserves all three conditions :

Mutual Exclusion is assured as only one process can access the critical section at any time.
Progress is also assured, as a process outside the critical section does not block other processes from entering the critical section.
Bounded Waiting is preserved as every process gets a fair chance.


Disadvantages of Peterson’s Solution
It involves Busy waiting
It is limited to 2 processes.
The algorithm uses two variables, flag and turn. A flag[n] value of true indicates that the process n wants to enter the critical section. Entrance to the critical section is granted for process P0 if P1 does not want to enter its critical section or if P1 has given priority to P0 by setting turn to 0.
P0: flag[0] = true;
P0_gate: turn = 1;
while (flag[1] == true && turn == 1)
{
// busy wait
}
// critical section
...
// end of critical section
flag[0] = false;



P1: flag[1] = true;
P1_gate: turn = 0;
while (flag[0] == true && turn == 0)
{
// busy wait
}
// critical section
...
// end of critical section
flag[1] = false;
Рекомендации по теме
Комментарии
Автор

I'm watching your lectures for 2 hours and tomorrow is my final exam of OS. Thank you Sir

helloworld
Автор

I have got cgpa of 9.40 just because of your vidoes sir

Rishikarangoli
Автор

So many channels failed to explain the concept which you were able to do well sir. Thank you a lot! May God bless you!

lalithav
Автор

Finally I understood very well. Thank you sir thanks a lot🙏

swethaakepogu
Автор

Thank you sir for explaining in a simple way sir

jaganc
Автор

goog explanation sir, zero knowledge person also can understand your teaching, awesome

jsagarbabu
Автор

Ur teaching is 👌iam studying two days before my exams

raziyasameera
Автор

Never understood process syn better tqsm 💖

whateverittakes
Автор

Thank you for this beautiful explanation sir

dkoqjrd
Автор

really you teach so gud line by line nd finally understood very well thank you so much sir

nisha.k
Автор

Good explaining concepts sir I
Like you

shivarajubg
Автор

Thank u very much sir for your clear explanation

binamonisaidulu
Автор

wonderful explanation sir 👏👏👏. you made it very simple

rahulvarma
Автор

Thank you sir... Very helpful explanation

shriyajukanti
Автор

best explanation! sharing this to all my friends

chaitanyag
Автор

thank you sir for your clear explanation

aravinderramreddy
Автор

sir, what will happen if we only put while(flag[ j ]==true); as the condition ?

sovahermanita
Автор

Good explanation sir, thank you sir...

jaswanthm
Автор

Amazing lecture.
I understood very clearly
Thank u sir

gopavaramsaimadhuree
Автор

Is Peterson’s Algorithm a good solution for Critical Section problem? If yes, then why? If no, then why?

stviewsshorts