生产者消费者问题:
Semaphore mutex=1;
Semaphore empty=n;
semaphore full=0;
Producer (){
While (1){
Produce an item in nextp;
P(empty);
P(mutex);
add;
V(mutex);
V(full);
}
}
Consumer (){
While(1){
P(full);
P(mutex);
remove;
V(empty);
V(mutex);
}
}
读者-写者问题