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.