Trying Again
This time, make one semaphore per chopstick
semaphore sem[5];
void philosopher(int i) {
while(1) {
sem[i]->P();
sem[((i+1)%5)]->P();
eat();
sem[i]->V();
sem[((i+1)%5)]->V();
think();
}
}
Previous slide
Next slide
Back to first slide
View graphic version