利用信号量描述前趋关系

进程间同步关系也可用前趋图表示。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

posted @ 2020-03-11 17:46  ice--cream  阅读(6449)  评论(0编辑  收藏  举报