jfcmacro

CrearSemFumadores.cpp

Mar 22nd, 2019
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <fcntl.h>           /* For O_* constants */
  2. #include <sys/stat.h>        /* For mode constants */
  3. #include <semaphore.h>
  4. #include <iostream>
  5. #include <cstdlib>
  6. #include <cstring>
  7. #include <cerrno>
  8. #include "nombres.h"
  9.  
  10. using namespace std;
  11.  
  12. int
  13. main(void) {
  14.   sem_t *semaforos[nSEM];
  15.  
  16.   for (int i = 0; i < nSEM; ++i) {
  17.     semaforos[i] = sem_open(nombres[i],
  18.                 O_CREAT | O_EXCL,
  19.                 S_IRUSR | S_IWUSR  | S_IRGRP | S_IWGRP, 0);
  20.     if (semaforos[i] == nullptr) {
  21.       cerr << "Error creando los semaforos: " << strerror(errno) << endl;
  22.     }
  23.  
  24.     sem_close(semaforos[i]);
  25.   }
  26.  
  27.   return EXIT_SUCCESS;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment