Basic Producer/Consumer
void Produce(int m) {
empty->P();
buf = m;
full->V();
}
int Consume() {
int m;
full->P();
m = buf;
empty->V();
return(m);
}
empty->Init(1);
full->Init(0);
int buf;
This use of a semaphore pair is called a split binary semaphore: the sum of the values is always one.
Previous slide
Next slide
Back to first slide
View graphic version