-
-
-
CENAPAD-MGCO
A seguir: Solução com Semáforos -
Acima: Semáforos
Anterior: Jantar dos Filósofos
Solução do Tanembaum ([Tanenbaum, 1987]):
#define N 5
#define LEFT (i-1)%N
#define RIGHT (i+1)%N
int state[N];
SEMAPHORE mutex = 1;
SEMAPHORE s[N]; /* todos iguais a zero inicialmente */
void philosopher(int i) {
while (TRUE) {
think();
take_forks(i);
eat();
put_forks(i);
}
}