Answers for "threads informatique"

0

threads informatique

sem_t mutex;     // init à 1
sem_t reveils[N];// init à 0
int etats[n];    // init à PENSE

void CommenceManger(int id) {
  sem_wait(mutex);
  etats[id] = FAIM;
  bool ok = etat[id-1] != MANGE
         && etat[id+1] != MANGE;
  if (ok) {
    etat[id] = MANGE;
    sem_post(mutex);
  } else {
    sem_post(mutex);
    sem_wait(reveils[id]);
  }
}
Posted by: Guest on December-08-2020

Browse Popular Code Answers by Language