ある製品はA、B、Cの3種類の部品を使って組み立てられ、3種類の部品はそれぞれ3つの相応の部品職場で生産されている.部品組立は組立作業場で行われ、組立作業場には3種類の部品をそれぞれ保管する棚S 1,S 2,S 3が3つあり、それぞれ最大m個のA部品、n個のB部品、k個のCを保管することができる.




  • ある製品はA、B、Cの3種類の部品を使って組み立てられ、3種類の部品はそれぞれ3つの相応の部品職場で生産されている.部品組立は組立作業場で完了し、組立作業場には3種類の部品をそれぞれ保管する棚S 1,S 2,S 3が3つあり、それぞれ最大m個のA部品、n個のB部品、k個のC部品を保管することができ、各製品はそれぞれA,B,Cの3種類の部品を1つずつ組み立てて構成されている.信号量とPV操作を用いて2つの生産組立の同期アルゴリズムを説明してください.
    1)データ構造定義共有データ変数(臨界資源)及び私有変数の定義
    int S1[m];//  A     
    int S2[n];//  B    
    int s3k];//  C     
    int inS1=0,outS1=0;//  A        
    int inS2=0,outS2=0;//  B        
    int inS3=0,outS3=0;//  C        
    

    2)プロセス部品組立プロセス定義部品Aを取り出し部品Bを取り出し部品Cを取り出し製品に組み立てる3)プロセス操作疑似コード実装
    #define m 10
    #define n 20
    #define k 30
    int S1[m];//  A     
    int S2[n];//  B     
    int S3[k];//  C     
    int inA=0,inB=0,inC=0;/      
    int outA=0,outB=0,outC=0;//      
    semaphore  Rs1=m;//  A       
    semaphore  Rs2=n;//  B       
    semaphore  Rs3=k;//  C       
    semaphore  numA=0; //  A   
    semaphore  numB=0;//  B   
    semaphore  numC=0;//  C   
    semaphore  semA=1; //  A      
    semaphore  semB=1; //  B      
    semaphore  semC=1;//  C      
    /*  A      */
    Process A()
    {
    		While(1)
    	{
    		    A  ;
    		P(Rs1);//   A      
    		P(semS1);//      A  
    		S1[inA]=  A;//    A
    		InA=(inA+1)%m;//      
    		V(semS1);//     
    		V(numA);//  A  1
    	}
    }
    /*  B      */
    Process B()
    {
    	While(1)
    	{
    		    B  ;
    		P(Rs2);//   B      
    		P(semS2);//      B  
    		S2[inB]=  B;//    B
    		InB=(inB+1)%n;//      
    		V(semS2);//     
    		V(numB);//  B  1
    	}
    }
    /*  C      */
    Process C()
    {
    	While(1)
    	{
    		    C  ;
    		P(Rs3);//   C      
    		P(semS3);//      C  
    		S1[inC]=  C;//    C
    		InC=(inC+1)%m;//      
    		V(semS3);//     
    		V(numC);//  C  1
    	}
    }
    /*        */
    Process produce()
    {
    	While(1)
    	{
    		P(numA);//     A
    		P(semS1);//      A  
    		  A=S1[outA]//    A
    		outA=(outA+1)%m;//      
    		V(semS1);//     
    		V(Rs2);//  B      1
    		P(numB);//     B
    		P(semS2);//      B  
    		  B=S2[outB]//    B
    		outB=(outB+1)%n;//      
    		V(semS2);//     
    		V(Rs2);//  B      1
    		P(numC);//     C
    		P(semS3);//      C  
    		  C=S3[outC]//    C
    		outC=(outC+1)%k;//      
    		V(semS3);//     
    		V(Rs3);//  C      1
    		  ;
    	}
    }