熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> 操作系統 >> 正文

十四 真經之過橋問題[7]

2022-06-13   來源: 操作系統 

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金典》

[]  []  []  []  []  []  []  []  


From:http://tw.wingwit.com/Article/program/czxt/201311/24217.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.