X-Git-Url: https://git.llucax.com/z.facultad/75.74/practicos.git/blobdiff_plain/671f9ad6c8665fefca79edc0f246f2d6a788136a..51f24d14e8c4c52776a98c8e2aaacf95f90ad1f4:/practicas/practica2/P02e2311.cpp?ds=inline diff --git a/practicas/practica2/P02e2311.cpp b/practicas/practica2/P02e2311.cpp index 18d1877..28cc9a0 100644 --- a/practicas/practica2/P02e2311.cpp +++ b/practicas/practica2/P02e2311.cpp @@ -18,7 +18,7 @@ using std::cout; using std::endl; // Nombre del pipe -#define PIPE "/tmp/77891_P02e2311" +#define PIPE "77891_P02e2311" // Prueba que un valor no sea -1, saliendo con error si es así. #define TEST(v) do { if ((v) == -1) { perror("P02e2221"); exit(200); } } while (0) @@ -26,17 +26,17 @@ using std::endl; /// Nombres de los procesos enum proc_t { PRODUCTOR, CONSUMIDOR }; -void producir(int pipe) +void producir(int p) { int val = rand(); - TEST(write(pipe, &val, sizeof(int))); + TEST(write(p, &val, sizeof(int))); cout << "Producido " << (int)val << endl; } -void consumir(int pipe) +void consumir(int p) { int val; - TEST(read(pipe, &val, sizeof(int))); + TEST(read(p, &val, sizeof(int))); cout << "Consumido " << val << endl; } @@ -57,14 +57,14 @@ int main(int argc, char *argv[]) max_iter = atoi(argv[2]); int mode = (proc == CONSUMIDOR) ? O_RDONLY : O_WRONLY; - int pipe = open(PIPE, mode); - TEST(pipe); + int p = open(PIPE, mode); + TEST(p); for (int i = 0; i < max_iter; ++i) { if (proc == PRODUCTOR) - producir(pipe); + producir(p); else - consumir(pipe); + consumir(p); sched_yield(); }