Пример #1
0
void serf(param * p, struct semS * sem, struct shmS * shm)
{
  signal(SIGUSR1, sigtermHandler);
//start
  char * whoami = "serf";
  int id;
  start(sem, shm, &(shm->idS), whoami, &id);
//vstup na molo
  bool captain = false;
  enterMolo(sem, shm, sem->boardS, sem->boardH, &(shm->s), &(shm->h), &captain, whoami, &id);
//vstup na palubu
  enterBoat(sem, shm, sem->boardS, &captain, whoami, &id);
//vypis role
  sayRole(sem, shm, &captain, whoami, &id);
// plavba
  rowBoat(p, sem, shm, &captain, whoami, &id);
//otevreni mola
  sem_wait(sem->shm);
  if (shm->onBoard == 12) { shm->onBoard = 0; sem_post(sem->molo);}
  sem_post(sem->shm);
//finish
  finish(p, sem, shm, "serf", &id);
  fclose(shm->out);
  closeSem(sem, shm);
  exit(EXIT_SUCCESS);
}
Пример #2
0
BlockingQueue::~BlockingQueue()
{
  pthread_mutex_lock(&queueLock);//wait till not in use
  while(!q_.empty())//remove all messages
  {
    delete q_.front();
    q_.pop();
  }
  pthread_mutex_unlock(&queueLock);
  pthread_mutex_destroy(&queueLock);
  closeSem(cntsemid_);
}