用信号量进程同步与互斥

6、

semaphore mutex=A, customer_count=0:
Cobegin
Customeri(){
p(mutex);
取号码,进入队列;
v(mutex);
v(customer_count);
}


serversi(){
while(A){
p(customer_count);
p(mutex);
从队列中取下一个号码;
v(mutex);
为该号码持有者服务;
}
}
Coend

8、

semaphore S1,S2;
S1=1;S2=0;
cobegin
      process P1(){
            begin
            repeat
            P(S1);
            拣白子
            V(S2);
            until false;
           end
        }
      process P2(){
           begin
           repeat
           P(S2);
           拣黑子
           V(S1);
           until false;
           end
       }
coend.

猜你喜欢

转载自www.cnblogs.com/ljgljg/p/10797432.html
今日推荐