Unit 3 QB
Unit 3 QB
Year/Class: II / CSE A, B
Course Title: Operating Systems
5. What are the requirements from any solution to critical section problem?
Mutual Exclusion, Progress, and Bounded Waiting.
Long answers
1. Write Peterson’s solution to 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.
do {
flag[i] = true;
turn = j;
while (flag[j] && turn == j);
/* critical section */
flag[i] = false;
/* remainder section */
}
while (true);
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] is true, 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[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. 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 −
2. Explain how semaphores can be used to solve critical section problem with producer consumer problem
3. Explain semaphore solution to reader write problem
4. Describe monitors and its operations
5. Describe deadlock prevention mechanisms
6. Write the banker’s algorithm for deadlock avoidance