Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following program that aims to solve the critical section problem f

ID: 3638786 • Letter: C

Question

Consider the following program that aims to solve the critical section problem for 2 processes P0 and P1:
1: var blocked: array [0..1] of boolean;
2: turn: 0..1;
3: procedure P (id: integer);
4: begin
5: repeat
6: blocked[id] := true;
7: while turn != id do
8: begin
9: while blocked[1-id] do no-op;
10: turn := id;
11: end;
12: < critical section >
13: blocked[id] := false;
14: < remainder >
15: until false
16: end
18: begin
19: blocked[0] := false; blocked[1] := false;
20: turn := 0;
21: parbegin
22: P(0); P(1)
23: parend
24: end
This is a proposed software solution to the mutual exclusion problem. Explain what mutual exclusion is.
Does this solution solve the mutual exclusion problem? Explain why or why not?

Explanation / Answer

before discussing mutual exclusion lets talk about critical sections in a program. A critical section of a process is a region where it modifies the shared variables.these shared variables are shared among other processes. Now ,Mutual exclusion makes sure that no two processes are in there critical section at the same time. i.e. only one process is modifying the shared resources at one time .other process trying to modify the variables must wait or in other words only one process can be in its critical section at a time,other processes trying to access the critical section must wait. this program satisfies the mutual exclusion criteria. following point illustrates this observation: process checks for its turn in line 7,in line 9 it waits for another process to complete its critical section execution ( which will be over when another process executes line 13),then it sets its turn for execution and enters the critical section in line 12.