Semaphores

As an aside, we also note another use for semaphores. They can be used with PARBEGIN .. PAREND to enable any precedence graph to be realized.

Our earlier precedence graph Solution
  S1  
  | \ 
  S2 S3
  | / \
  S4   S5
   \  /
    S6
S1;
PARBEGIN
      BEGIN S2; V(a); END;
      BEGIN S3; V(b); V(c); END;
      BEGIN P(a); P(b); S4; END;
      BEGIN P(c); S5; END;
PAREND;
S6;
-- all semaphores initially 0

-- semaphore a guarantees S2 precedes S4
-- semaphores b, c guarantee that S3
-- precedes both S4 and S5