// agua.cc // Makes water to see if user program is working // // Copyright (c) 1992-1993 The Regents of the University of California. // All rights reserved. See copyright.h for copyright notice and limitation // of liability and disclaimer of warranty provisions. #include "copyright.h" #include "system.h" #include "synch.h" //--------------------------------------------------------------------- Semaphore sH("Semáforo H", 0), sO("Semáforo O", 0); int hContador = 0, oContador = 0; void H(int ch) { hContador++; if(hContador > 1 && oContador > 0) { hContador=-2; oContador--; printf("Haciendo agua!!\n"); sH.V(); sO.V(); } else { sH.P(); } } void O(int co) { oContador++; if(hContador > 1) { hContador=-2; oContador--; printf("Haciendo agua!!\n"); sH.V(); sH.V(); } else { sO.P(); } } void haceHilo() { Thread * t; t = new Thread("Creador de Hilos\n"); if(Random()%3) t->Fork(H,0); else t->Fork(O,0); } int main() { DEBUG('t', "Entering Agua Thread"); for(int i=0;i<30;i++) haceHilo(); return 0; }