jfcmacro icon

Agente.cpp

jfcmacro | PRO | 03/22/19 04:53:09 PM UTC | 0 ⭐ | 461 👁️ | Never ⏰ | []
C++ |

640 B

|

None

|

0 👍

/

0 👎

#include <fcntl.h>           /* For O_* constants */
#include <sys/stat.h>        /* For mode constants */
#include <semaphore.h>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cerrno>
#include "nombres.h"
 
using namespace std;
 
static void agente(sem_t *[]);
 
int
main(void) {
 
  sem_t *semaforos[nSEM];
 
  for (int i = 0; i < nSEM; ++i) {
    semaforos[i] = sem_open(nombres[i], 0);
  }
 
  agente(semaforos);
 
  return EXIT_SUCCESS;
}
 
 
static void agente(sem_t *semaforos[]) {
 
  for (;;) {
    cout << "Ofertando" << endl;
    int fumador = rand() % 3;
    sem_post(semaforos[fumador]);
    sem_wait(semaforos[nSEM - 1]);
  }
}

Comments