begin var Smutex=Nmutex=mutex=:semaphore; SCarCount=NCarCount=:integer; cobegin process Scari(i=) begin p(Smutex); if(SCarCount=)then p(mutex); SCarCount=SCarCount+; v(Smutex); 过桥 p(Smutex); SCarCount=SCarCount; if(SCarCount=)then v(mutex); v(Smutex); end process Ncarj(j=) begin p(Nmutex); if(NCarCount=)then p(mutex); NCarCount=NCarCount+; v(Nmutex); 过桥 p(Nmutex); NCarCount=NCarCount; if(NCarCount=)then v(mutex); v(Nmutex); end coend end 返回《操作系统之PV金典》 [] [] [] [] [] [] [] [] |