Given the following series of statements, construct a precedence graph:
S1: a := b + c; S2: d := e - f; S3: g := a; S4: h := g; S5: g := 0; S6: i := b * c; S7: j := h * i;
Given the following precedence graph:
Construct an equivalent program fragment that makes maximum use of parallelism, using PARBEGIN .. PAREND. (Hint: you will need more than one PARBEGIN .. PAREND pair).
Repeat, using FORK and JOIN. (Again, you will need more than one of each.)
Suppose we now add to the graph an edge from S2 to S4. Explain why the full potential parallelism of the new graph cannot be realized using PARBEGIN .. PAREND.
Show how the full parallelism possible in the new graph can be realized by using PARBEGIN .. PAREND in conjunction with semaphores.
Do problem 6.2 in the text.
Consider the following proposed solution to the critical section problem for two processes. Either present an argument that it is correct, or show an example that violates one of the three requirements for a solution to the critical section problem.
(* The two processes P0 and P1 share the following variables *)
var flag: array[0..1] of boolean; (* Initially false *)
turn: 0..1;
(* Each process executes the following code, where i = 0 for process P0
and 1 for process P1 *)
repeat
flag[i] := true;
while turn <> i do
begin
while flag[1 - i] do skip;
turn := i
end;
...
(* critical section *)
...
flag[i] := false;
...
(* remainder section *)
...
until forever
Suppose a certain machine has the swap instruction, defined as follows:
Give code for this machine for the binary semaphore primitives P and V.