進程間同步關系也可用前趨圖表示。C和P兩進程先計算好再打印同步關系前趨圖如下:
對應這個前趨關系可設置同步信號量full,它為后繼進程P擁有,初值為0.它的並發執行程序如下:
vat full : semaphore: =0;
begin
parbegin
C:begin Compute : V(full) : end
P:begin P(full) : Print : end
parend
End
例題:
var a1,a2,a3,a4,a5,a6,a7:semaphore: =0;
begin
parbegin
s1:begin s1; V(a1) ; V(a2) ; end
s2:begin P(a1) ; s2 ; V(a4) ; V(a5) ; end
s3:begin P(a1) ; s3 ; V(a6) ; end
s4:begin P(a2) ; s4 ; V(a6) ; end
s5:begin P(a2) ; s5 ; V(a6) ; end
s6:begin P(a3) ; P(a4) ; P(a5) ; s6 ; end