
2.3 Parallelization of an Example Program 107
Pi P
2
A = 1;
b:
flag = 1;
a: while (flag is 0) do nothing;
print A;
FIGURE 2.14 Point-to-point event synchronization using flags. Suppose we want to
ensure that a process Pj does not get past a certain point
(say,
a) in the program until some
other process P
2
has already reached another point (say, b). Assume that the variable flag
(and A) was initialized to 0 before the processes arrived at this scenario. If
P
1
gets to state-
ment a after P
2
has already executed statement b, Pi will simply pass point a. If, on the
other hand, P
2
has not yet executed b, then P
1
will remain in the "idle" while loo ...