begin var S1,S2,SAB:semaphore =1,1,1; C1,C2:integer =0,0; process A-i(i=1,2) begin repeat P(SAB); C1 = C1+1; if(C1=1) then P(S2); V(SAB); 读文件F; P(SAB) C1 = C1-1; if(C1==0)V(S2) V(SAB) until false end process B-i(i=1,2) begin repeat P(SAB); C2 = C2+1; if(C2=1) then P(S1); V(SAB); 读文件F; P(SAB) C2 = C2-1; if(C2==0)V(S1) V(SAB) until false end end