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>
- using namespace std;
- int
- main(void) {
- const char *nombres[] = { "notabaco", "nopapel", "nocerilla" };
- sem_t *semaforos[3];
- for (long unsigned i = 0; i < 3; ++i) {
- semaforos[i] = sem_open(nombres[i],
- O_CREAT | O_EXCL,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, 0);
- if (semaforos[i] == nullptr) {
- cerr << "Error creando los semaforos: " << strerror(errno) << endl;
- }
- sem_close(semaforos[i]);
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment