0% found this document useful (0 votes)
7 views1 page

Peterson's Solution for Critical Sections

Uploaded by

nilaja2003
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Peterson's Solution for Critical Sections

Uploaded by

nilaja2003
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Q2. Apply Peterson’s solution to critical section problem and explain.

Ans: This is a classic software-based solution to the critical section problem.


✓ 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 requirements of
mutual exclusion, progress, and bounded waiting.
✓ Peterson’s solution is restricted to two processes that alternate execution between their critical section and
remainder sections. The processes are numbered P0 and P1 or Pi and Pj where j=1-i
✓ Peterson’s solution requires the two processes to share two data items:
int turn;
boolean flag[2];
✓ turn: The variable turn indicates whose turn it is to enter its critical section. Example: If turn==i, then process
Pi is allowed to execute in its critical section.
✓ flag: the flag array is used to indicate if a process is ready to enter its critical section. Example: If flag[i] is true,
this value indicates that Pi is ready to enter its critical section.
✓ To enter the critical section, process Pi first sets flag[i] 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.
✓ If both processes try to enter at the same time, turn will be set to both i and j at roughly the same time. Only
one of these assignments will last, the other will occur but will be overwritten immediately.
✓ The eventual value of the turn determines which of the two processes is allowed to enter its critical section.
✓ To prove that the solution is correct, it must be proved that:
1. Mutual exclusion is preserved
2. Progress requirement is satisfied
3. Bounded waiting requirement is met

_______________________________________________________________________________________________

You might also like