UFMG - Pós-graduação em Ciência da Computação - Programação Paralela

A seguir: Jantar dos Filósofos com Acima: Sincronização com Memória Compartilhada Anterior: Produtor/Consumidor com semáforos


Jantar dos Filósofos com Semáforos - 1

([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);
  }
}



Osvaldo Carvalho