Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment