Esempio n. 1
0
TEST(core, Semaphore)
{
    Semaphore s;

    ASSERT_FALSE(s.wait(10));

    s.signal();
    ASSERT_TRUE(s.wait(10));
    ASSERT_FALSE(s.wait(10));

    s.signal(2);
    ASSERT_TRUE(s.wait(10));
    ASSERT_TRUE(s.wait(10));
    ASSERT_FALSE(s.wait(10));

    std::thread t1([&s]() {
        ASSERT_FALSE(s.wait(10));

        s.wait();
    });

    std::thread t2([&s]() {
        std::this_thread::sleep_for(std::chrono::milliseconds(50));

        s.signal(2);

        s.wait();
    });

    t1.join();
    t2.join();
}
Esempio n. 2
0
    void testSimple()
    {
        //Some very basic semaphore tests.
        Semaphore sem;
        sem.signal();
        sem.wait();
        testTimedElapsed(sem, 100);
        sem.signal();
        testTimedAvailable(sem);

        sem.reinit(2);
        sem.wait();
        testTimedAvailable(sem);
        testTimedElapsed(sem, 5);
    }
Esempio n. 3
0
  // returns false if queue was full
  bool tryPut(T t){
    if (queue.bounded_push(t)) {
      ready.signal();
      return true;
    }

    return false;
  }
 BigRealResourcePool &getInstance() {
   m_gate.wait();
   if(m_instance == NULL) {
     m_instance = new BigRealResourcePool; TRACE_NEW(m_instance);
   }
   m_gate.signal();
   return *m_instance;
 }
Esempio n. 5
0
	virtual void run() {
		Looper::prepare();
		sLooper2 = Looper::myLooper();
		sHandler2 = new Handler2();
		printf("Looper 2 uses thread %d\n", (int32_t) pthread_self());
		sSemaphore2.signal();
		Looper::loop();
	}
Esempio n. 6
0
 simple_queue(unsigned int queue_size) 
 {
     element_count = queue_size;
     elements = new _et[element_count];
     free_space.signal(element_count);
     active_buffers = 0;
     first = 0;
     last = 0;
 }
Esempio n. 7
0
void barber(){
    while(true){
        semCustomers.wait();
        bool blockBarber = false;
        if(cntCustomers == 0)
            blockBarber = true;
        semCustomers.signal();

        if(blockBarber)
            sleep.wait();

        mutex.signal();

        semCustomers.wait();
        cntCustomers--;
        semCustomers.signal();
    }
}
Esempio n. 8
0
void customer(){
    semCustomers.wait();
    if(cntCustomers == N){
        semCustomers.signal();
        return;
    }

    if(cntCustomers == 0){
        cntCustomers++;
        sleep.signal();
    }
    else{
        cntCustomers++;
    }
    semCustomers.signal();

    mutex.wait();
}
Esempio n. 9
0
 void pop (_et &element) 
 {
     data_avail.wait();
     c_region.enter();
     element = elements[first];
     first = (first + 1) % element_count;
     active_buffers--;
     c_region.leave();
     free_space.signal();
 }
Esempio n. 10
0
  void worker_done_with_task() {
    // Mark that the worker is done with the task.
    // The worker is not allowed to read the state variables after this line.
    uint not_finished = (uint) Atomic::add(-1, (volatile jint*)&_not_finished);

    // The last worker signals to the coordinator that all work is completed.
    if (not_finished == 0) {
      _end_semaphore->signal();
    }
  }
Esempio n. 11
0
int ReceiveThread::run()
{
    ISocket * socket = ISocket::create(3456);
    ISocket * client = socket->accept();
    StringBuffer result;
    readResults(client, parallelBlocked, false, result, nullptr, 0);
    client->Release();
    socket->Release();
    finishedReading.signal();
    return 0;
}
Esempio n. 12
0
 void push(const _et &element)
 {
     free_space.wait();
     c_region.enter();
     int next = (last + 1) % element_count;
     elements[last] = element;
     last = next;
     active_buffers++;
     c_region.leave();
     data_avail.signal();
 }
Esempio n. 13
0
 void testSimple()
 {
     //Very basic semaphore stress tests.
     Semaphore sem;
     sem.signal();
     if (!sem.wait(1000))
     {
         VStringBuffer errMsg("Semaphore stalled (%s:%s)", sanitizeSourceFile(__FILE__), __LINE__);
         CPPUNIT_FAIL(errMsg.str());
     }
     testTimedElapsed(sem, 5, 1000);
 }
Esempio n. 14
0
int main(int argc, char **argv)
{
	char buffer[TAM_BUFFER];

	if (argc != 2) {
		strcpy (buffer, "Error: Cantidad de parametros invalida\n");
		write (fileno(stderr),buffer, strlen(buffer));
		exit(1);
	}
	
	int cantProcesos = 0;
	sscanf(argv[1] , "%d", &cantProcesos);
	
	// Creando semaforo de control de acceso a la memoria compartida
	Semaphore semControl = Semaphore();	
	semControl.createSemaphore((char *)DIRECTORY, ID_SEMCONTROL, 1);
	semControl.initializeSemaphore(0, 1);

	// Creando semaforos de control de los procesos
	Semaphore semProductores = Semaphore();
	semProductores.createSemaphore((char *)DIRECTORY, ID_SEMPRODUCTORES, cantProcesos);
	for (int nroSemaforo = 0; nroSemaforo < cantProcesos; nroSemaforo++) {
	 	semProductores.initializeSemaphore(nroSemaforo, 1);
	}
	
	// Creando la memoria compartida
	CountingSharedMemory shMem = CountingSharedMemory();
	shMem.createSharedMemory((char *)DIRECTORY, ID_SHMEM);
	semControl.wait(0);
	{	
		int p = 0;
		shMem.writeInfo(&p);
	}
	semControl.signal(0);
		
	for (int i = 0; i < cantProcesos; i++) {
		pid_t pid = fork();
		if (pid == 0) {
			char nroProductor[TAM_BUFFER];
			sprintf(nroProductor,"%d",i);
						
			execlp("./productor", "productor", nroProductor, argv[1], (char *) 0);
			sprintf(buffer, "Launcher Error: %s\n", strerror(errno));
			write(fileno(stdout), buffer, strlen(buffer));
		}
		//sleep (1);
	}		
	
	sprintf(buffer, "Launcher Terminado \n");
	write(fileno(stdout), buffer, strlen(buffer));
			
	return 0;
}
Esempio n. 15
0
static void addDebugLine(_In_z_ _Printf_format_string_ TCHAR const * const format, ...) {
  static Semaphore gate;
  static TCHAR *mode = _T("w");
  gate.wait();
  FILE *f = FOPEN(_T("c:\\temp\\semaphore.log"),mode);
  mode = _T("a");
  va_list argptr;
  va_start(argptr,format);
  _vftprintf(f, format, argptr);
  va_end(argptr);
  fclose(f);
  gate.signal();
}
Esempio n. 16
0
 void subsort(unsigned s, unsigned n)
 {
     do {
         sJobItem *qi;
         while (n>PARALLEL_GRANULARITY) {
             unsigned r1;
             unsigned r2;
             partition(s, n, r1, r2);
             unsigned n2 = n+s-r2;
             if (r1==s) {
                 n = n2;
                 s = r2;
             }
             else {
                 if (n2!=0) {
                     qi = new sJobItem;
                     qi->num = n2;
                     qi->start = r2;
                     NonReentrantSpinBlock block(joblock);
                     jobq.enqueue(qi);
                     if (waiting) {
                         jobqsem.signal(waiting);
                         waiting = 0;
                     }
                 }
                 n = r1-s;
             }
         }
         serialsort(s,n);
         NonReentrantSpinBlock block(joblock);
         if (waiting==numsubthreads) { // well we are done so are rest
             done = true;
             jobqsem.signal(waiting);
             break;
         }
     }
     while(waitForWork(s,n));
 }
Esempio n. 17
0
 bool push(const _et &element,long timeout)
 {
     if (free_space.wait(timeout) ) {
         c_region.enter();
         int next = (last + 1) % element_count;
         elements[last] = element;
         last = next;
         active_buffers++;
         c_region.leave();
         data_avail.signal();
         return true;
     }
     return false;
 }
Esempio n. 18
0
    inline int wait() {
        int ret = 0;
        barlock.lock();
        current += 1;
        if(current == count) {
            ret = PTHREAD_BARRIER_SERIAL_THREAD;
            for(int i=0; i<count; i++) {
                barrier1.signal();
            }
        }
        barlock.unlock();
        barrier1.wait(); // wait for n threads to arrive

        barlock.lock();
        current -= 1;
        if(current == 0) {
            for(int i=0; i<count; i++) {
                barrier2.signal();
            }
        }
        barlock.unlock();
        barrier2.wait();
        return ret;
    }
Esempio n. 19
0
  inline bool wait() {
    bool ret = false;
    barlock.lock();
    current += 1;
    if(current == count) {
      ret = true;
      for(int i=0; i<count;i++) {
        barrier1.signal();
      }
    }
    barlock.unlock();
    barrier1.wait(); // wait for n threads to arrive

    barlock.lock();
    current -= 1;
    if(current == 0) {
      for(int i=0;i<count;i++) {
        barrier2.signal();
      }
    }
    barlock.unlock();
    barrier2.wait();
    return ret;
  }
Esempio n. 20
0
  void coordinator_execute_on_workers(AbstractGangTask* task, uint num_workers) {
    // No workers are allowed to read the state variables until they have been signaled.
    _task         = task;
    _not_finished = num_workers;

    // Dispatch 'num_workers' number of tasks.
    _start_semaphore->signal(num_workers);

    // Wait for the last worker to signal the coordinator.
    _end_semaphore->wait();

    // No workers are allowed to read the state variables after the coordinator has been signaled.
    assert(_not_finished == 0, "%d not finished workers?", _not_finished);
    _task    = NULL;
    _started = 0;

  }
Esempio n. 21
0
 void unlock(SessionId owner)
 {
     sect.enter();
     if (exclusivenest) {
         exclusivenest--;
         if (exclusivenest) { // still locked
             assertex(owners.item(0)==owner);
             sect.leave();
             return;
         }
     }
     verifyex(owners.zap(owner));
     if (owners.ordinality()==0) {
         exclusivenest = 0;
         if (waiting) {
             sem.signal(waiting);
             waiting = 0;
         }
     }
     else {
         assertex(!exclusivenest);
     }
     sect.leave();
 }
Esempio n. 22
0
 bool waitForWork(unsigned &s,unsigned &n)
 {
     NonReentrantSpinBlock block(joblock);
     while (!done) {
         sJobItem *qi = jobq.dequeue();
         if (qi) {
             s = qi->start;
             n = qi->num;
             delete qi;
             return true;
         }
         if (waiting==numsubthreads) { // well we know we are done and so are rest so exit
             done = true;
             jobqsem.signal(waiting);
             break;
         }
         waiting++;
         NonReentrantSpinUnblock unblock(joblock);
         jobqsem.wait();
     }
     s = 0; // remove uninitialised variable warnings
     n = 0;
     return false;
 }
Esempio n. 23
0
 ~Schedule()
 {
     stopping = true;
     semSchedule.signal();
     join();
 }
int main(int argc, char** argv) {

    /* Se crean e inician todos los ipc necesarios para
     * el funcionamiento del proceso.
     */
    ComunicacionRobot5MessageQueue colaComunicacionRobot5 = ComunicacionRobot5MessageQueue();
    
    PedidosAgvMessageQueue colaPedidos = PedidosAgvMessageQueue();
        
    BufferCanastoSharedMemory bufferCanasto[3];
    Semaphore semaforoAccesoBufferAgv;
    Semaphore semaforoBloqueoAgv;
    
    try {
        iniciarIPC(colaComunicacionRobot5, colaPedidos, bufferCanasto, semaforoAccesoBufferAgv, semaforoBloqueoAgv);
    }
    catch (IPCException const& ex) {
        char buffer[TAM_BUFFER];
        sprintf (buffer, "Controlador Robot 5 - AGV: Error: %s\n", ex.what());
        write (fileno(stderr),buffer, strlen(buffer));
        exit(-1);
    }
    
    char buffer[TAM_BUFFER];
    sprintf(buffer, "Controlador Robot 5 - AGV: Iniciando.\n");
    write(fileno(stdout), buffer, strlen(buffer));
    
    bool deboSeguir = true;
    
    while (deboSeguir) {
        try {
            /* Obtengo un pedido de alguno de los AGV */
            sprintf(buffer, "Controlador Robot 5 - AGV: Esperando un pedido por parte de un AGV.\n");
            write(fileno(stdout), buffer, strlen(buffer));
            
            MensajePedidoAgv *nuevoPedido;
            colaPedidos.recibirPedidoAgv(TIPO_PEDIDO_CANASTO, nuevoPedido);
            
            sprintf(buffer, "Controlador Robot 5 - AGV: Recibió un pedido de un AGV.\n");
            write(fileno(stdout), buffer, strlen(buffer));
            
            /* Le envio el pedido al robot 5 Aplicacion */
            PedidoRobot5 pedidoRobot5;
            pedidoRobot5.pedidoCanasto = (*nuevoPedido).pedidoCanasto;
            pedidoRobot5.tipo = PEDIDO_CANASTO;

            MensajePedidoRobot5 mensajePedidoRobot5;
            mensajePedidoRobot5.mtype = TIPO_PEDIDO_ROBOT_5;
            mensajePedidoRobot5.pedidoRobot5 = pedidoRobot5;

            sprintf(buffer, "Controlador Robot 5 - AGV: Le envio un pedido de canasto al robot 5.\n");
            write(fileno(stdout), buffer, strlen(buffer));
            colaComunicacionRobot5.enviarPedidoRobot5(mensajePedidoRobot5);

            /* Me quedo esperando la respuesta del robot 5 */
            MensajeRespuestaCanasto mensajeRespuestaCanasto;
            colaComunicacionRobot5.recibirCanasto(TIPO_MENSAJE_RESPUESTA_CANASTO_ROBOT_5, &mensajeRespuestaCanasto);
            sprintf(buffer, "Controlador Robot 5 - AGV: Recibió la respuesta del robot 5 para el AGV %d.\n",mensajeRespuestaCanasto.idAgv);
            write(fileno(stdout), buffer, strlen(buffer));
                       
            /* Una vez recibido el canasto requerido, se lo envio al agv correspondiente.
             * Intento acceder al buffer del agv al que va destinado al pedido.  
             */
            semaforoAccesoBufferAgv.wait(mensajeRespuestaCanasto.idAgv);
            {
                sprintf(buffer, "Controlador Robot 5 - AGV: Accedo al buffer del canasto para el AGV: %d.\n",mensajeRespuestaCanasto.idAgv);
                write(fileno(stdout), buffer, strlen(buffer));

                /* Una vez obtenido al acceso, dejo el canasto. */
                bufferCanasto[mensajeRespuestaCanasto.idAgv - 1].writeInfo(&mensajeRespuestaCanasto.canasto);
            }
            /* Libero al AGV para que este retire el canasto */
            semaforoBloqueoAgv.signal(mensajeRespuestaCanasto.idAgv);
            
            sprintf(buffer, "Controlador Robot 5 - AGV: Libero al AGV %d.\n",mensajeRespuestaCanasto.idAgv);
            write(fileno(stdout), buffer, strlen(buffer));

            /* Libero el buffer del canasto */
            semaforoAccesoBufferAgv.signal(mensajeRespuestaCanasto.idAgv);
        }
        catch (IPCException const& ex) {
            char buffer[TAM_BUFFER];
            sprintf(buffer, "Controlador Robot 5 - AGV:Error: %s\n", ex.what());
            write(fileno(stderr), buffer, strlen(buffer));
            exit(-1);
        }
    }
    
    return 0;
}
Esempio n. 25
0
 void next()
 {
     hold.signal();
 }
Esempio n. 26
0
 void kill()         // called on message thread
 {
     terminate = true;
     hold.signal();
 }
Esempio n. 27
0
int main(int argc, char **argv)
{
	char buffer[TAM_BUFFER];

	if (argc != 2) {
		strcpy (buffer, "Error Puerta Entrada: Cantidad de parametros invalida\n");
		write (fileno(stderr),buffer, strlen(buffer));
		exit(1);
	}

	srand (time(NULL));

	int totalPuerta = 0;

	int nroPuerta = 0;
	sscanf(argv[1] , "%d", &nroPuerta);
	
	sprintf(buffer, "Puerta Entrada: %d Iniciando\n", nroPuerta);
	write(fileno(stdout), buffer, strlen(buffer));
	
	// Creando semaforo de control de acceso a la memoria compartida
	Semaphore semControl = Semaphore();	
	if (semControl.getSemaphore((char *)DIRECTORY, ID_SEMCONTROL, 1) != 0) {
		sprintf (buffer, "Puerta Entrada: %d Fallo al obtener el semaforo de control\n", nroPuerta);
		write (fileno(stderr),buffer, strlen(buffer));
		exit(-1);
	}

	// Obteniendo memoria compartida
	InfoMuseoSharedMemory shMem = InfoMuseoSharedMemory();
	if (shMem.getSharedMemory((char *)DIRECTORY, ID_SHMEM) != 0) {
		sprintf (buffer, "Puerta Entrada: %d Fallo al obtener la memoria\n", nroPuerta);
		write (fileno(stderr),buffer, strlen(buffer));
		exit(-1);
	}

	bool deboSeguir = true;
	
	while (deboSeguir) {
		
		int dormir = rand() % 5 + 1;
		sprintf (buffer, "Puerta Entrada: %d Durmiendo por %d segundos\n", nroPuerta, dormir);
		write (fileno(stdout),buffer, strlen(buffer));
		usleep(dormir*1000*1000);
		
		totalPuerta++;
		
		sprintf (buffer, "Puerta Entrada: %d Llego la persona %d\n", nroPuerta, totalPuerta);
		write (fileno(stdout),buffer, strlen(buffer));
		
		int semaphoreOperation = semControl.wait(0);
		if (semaphoreOperation == -1) exit(-1);
		{
			InfoMuseo *info =  shMem.readInfo();	
			if (! (*info).abierto) {
				sprintf (buffer, "Puerta Entrada: %d El museo esta CERRADO, la persona %d debe irse\n", nroPuerta,totalPuerta);
				write (fileno(stdout),buffer, strlen(buffer));
			}
			else {
				if ((*info).cantidad == (*info).cantidadMaxima) {
					sprintf (buffer, "Puerta Entrada: %d El museo esta LLENO, la persona %d debe irse\n", nroPuerta,totalPuerta);
					write (fileno(stdout),buffer, strlen(buffer));					
				}
				else {
					sprintf (buffer, "Puerta Entrada: %d La persona %d ingresa al museo\n", nroPuerta,totalPuerta);
					write (fileno(stdout),buffer, strlen(buffer));

					(*info).cantidad++;
					(*info).total++;	
					shMem.writeInfo(info);
				}
			}			
		}
		semControl.signal(0);
		if (semaphoreOperation == -1) exit(-1);
	}
	
	return 0;
}
Esempio n. 28
0
    void processMessage(CMessageBuffer &mb)
    {
        ICoven &coven=queryCoven();
        SessionId id;
        int fn;
        mb.read(fn);
        switch (fn) {
        case MSR_REGISTER_PROCESS_SESSION: {
                acceptConnections.wait();
                acceptConnections.signal();
                Owned<INode> node(deserializeINode(mb));
                Owned<INode> servernode(deserializeINode(mb));  // hopefully me, but not if forwarded
                int role=0;
                if (mb.length()-mb.getPos()>=sizeof(role)) { // a capability block present
                    mb.read(role);
                    if (!manager.authorizeConnection(role,false)) {
                        SocketEndpoint sender = mb.getSender();
                        mb.clear();
                        coven.reply(mb);
                        MilliSleep(100+getRandom()%1000); // Causes client to 'work' for a short time.
                        Owned<INode> node = createINode(sender);
                        coven.disconnect(node);
                        break;
                    }
#ifdef _DEBUG
                    StringBuffer eps;
                    PROGLOG("Connection to %s authorized",mb.getSender().getUrlStr(eps).str());
#endif
                }
                
                IGroup *covengrp;
                id = manager.registerClientProcess(node.get(),covengrp,(DaliClientRole)role);
                mb.clear().append(id);
                if (covengrp->rank(servernode)==RANK_NULL) { // must have been redirected
                    covengrp->Release(); // no good, so just use one we know about (may use something more sophisticated later)
                    INode *na = servernode.get();
                    covengrp = createIGroup(1, &na);
                }
                covengrp->serialize(mb);
                covengrp->Release();
                coven.reply(mb);
            }
            break;
        case MSR_SECONDARY_REGISTER_PROCESS_SESSION: {
                mb.read(id);
                Owned<INode> node (deserializeINode(mb));
                int role;
                mb.read(role);
                manager.addProcessSession(id,node.get(),(DaliClientRole)role);
                mb.clear();
                coven.reply(mb);
            }
            break;
        case MSR_REGISTER_SESSION: {
                SecurityToken tok;
                SessionId parentid;
                mb.read(tok).read(parentid);
                SessionId id = manager.registerSession(tok,parentid);
                mb.clear().append(id);
                coven.reply(mb);
            }
            break;
        case MSR_SECONDARY_REGISTER_SESSION: {
                mb.read(id);
                manager.addSession(id);
                mb.clear();
                coven.reply(mb);
            }
            break;
        case MSR_LOOKUP_PROCESS_SESSION: {
                // looks up from node or from id
                Owned<INode> node (deserializeINode(mb));
                if (node->endpoint().isNull()&&(mb.length()-mb.getPos()>=sizeof(id))) {
                    mb.read(id);
                    INode *n = manager.getProcessSessionNode(id);
                    if (n)
                        node.setown(n);
                    node->serialize(mb.clear());
                }
                else {
                    id = manager.lookupProcessSession(node.get());
                    mb.clear().append(id);
                }
                coven.reply(mb);
            }
            break;
        case MSR_STOP_SESSION: {
                SessionId sessid;
                bool failed;
                mb.read(sessid).read(failed);
                manager.stopSession(sessid,failed);
                mb.clear();
                coven.reply(mb);
            }
            break;
        case MSR_LOOKUP_LDAP_PERMISSIONS: {
                StringAttr key;
                StringAttr obj;
                Owned<IUserDescriptor> udesc=createUserDescriptor();
                StringAttr username;
                StringAttr passwordenc;
                mb.read(key).read(obj);
                udesc->deserialize(mb);
#ifndef _NO_DALIUSER_STACKTRACE
                //following debug code to be removed
                StringBuffer sb;
                udesc->getUserName(sb);
                if (0==sb.length())
                {
                    DBGLOG("UNEXPECTED USER (NULL) in dasess.cpp CSessionRequestServer::processMessage() line %d", __LINE__);
                }
#endif
                unsigned auditflags = 0;
                if (mb.length()-mb.getPos()>=sizeof(auditflags))
                    mb.read(auditflags);
                int err = 0;
                int ret=manager.getPermissionsLDAP(key,obj,udesc,auditflags,&err);
                mb.clear().append(ret);
                if (err)
                    mb.append(err);
                coven.reply(mb);
            }
            break;
        }
    }
Esempio n. 29
0
 void ready()
 {
     acceptConnections.signal();
 }
Esempio n. 30
0
int main(int argc, char **argv)
{
	char buffer[TAM_BUFFER];

	if (argc != 3) {
		strcpy (buffer, "Launcher: Error: Cantidad de parametros invalida\n Uso:\n ./launcher [CANT BUSES] [CANT PERSONAS]\n");
		write (fileno(stderr),buffer, strlen(buffer));
		exit(-1);
	}
	
	int cantBuses = 0;
	sscanf(argv[1] , "%d", &cantBuses);
	if (cantBuses > MAX_BUSES) {
		sprintf (buffer, "Launcher: Error: Cantidad de buses debe ser menor que %d\n", MAX_BUSES);
		write (fileno(stderr),buffer, strlen(buffer));
		exit(-1);
	}

	int cantPersonas = 0;
	sscanf(argv[2] , "%d", &cantPersonas);

	sprintf(buffer, "Launcher: Cantidad buses: %d Cantidad Personas: %d\n", cantBuses, cantPersonas);
	write(fileno(stdout), buffer, strlen(buffer));

	Semaphore semControlSala = Semaphore();	
	Semaphore semPuerta = Semaphore();
	Semaphore semBuses = Semaphore();
	IntercambioMessageQueue intercambioMessageQueue = IntercambioMessageQueue();
	InfoSalaSharedMemory shMemSala = InfoSalaSharedMemory();
	
	try {
		// Creando semaforo de control de acceso a la memoria compartida Sala
		semControlSala.createSemaphore((char *)DIRECTORY, ID_SEM_CONTROL_SALA, 1);
		semControlSala.initializeSemaphore(0, 1);

		// Creando semaforo de bloqueo de la puerta
		semPuerta.createSemaphore((char *)DIRECTORY, ID_SEM_PUERTA, 1);
		semPuerta.initializeSemaphore(0, 0);
		
		// Creando semaforo de bloqueo de buses
		semBuses.createSemaphore((char *)DIRECTORY, ID_SEM_BUSES, cantBuses);
		for (int i = 0; i < cantBuses; ++i) {
			semBuses.initializeSemaphore(i, 0);
		}
		
		for (int i = 0; i < cantBuses; ++i) {
			semBuses.signal(i);
			sprintf(buffer, "Launcher: Probando sem bus: %d\n", i);
			write(fileno(stdout), buffer, strlen(buffer));		
			semBuses.wait(i);
			sprintf(buffer, "Launcher 2: Probando sem bus: %d\n", i);
			write(fileno(stdout), buffer, strlen(buffer));
		}
	
		// Creando la cola de mensajes de intercambio
		intercambioMessageQueue.create((char*)DIRECTORY, ID_COLA_PERSONAS);

		// Creando memoria compartida Sala
		shMemSala.createSharedMemory((char *)DIRECTORY, ID_SHMEM_SALA);
		InfoSala informacionSala;
		informacionSala.puertaBloqueada = false;
		informacionSala.busEnSala = false;
		for (int i = 0; i < TAM_SALA; ++i) {
			informacionSala.idPersonas[i] = 0;
		}
		for (int i = 0; i < cantBuses; ++i) {
			informacionSala.busBloqueado[i] = false;
		}	
		semControlSala.wait(0);
		{
			shMemSala.writeInfo(&informacionSala);
		}		
		semControlSala.signal(0);
	}
	catch (IPCException &ex) {
		sprintf (buffer, "Launcher Error: %s\n", ex.getDescription());
		write (fileno(stderr),buffer, strlen(buffer));
		exit(-1);
	}

	// Creando Buses
	static char cantidadBuses[TAM_BUFFER];
	sprintf(cantidadBuses, "%d",cantBuses);
	for (int i = 0; i < cantBuses; i++) {
		static char nroBus[TAM_BUFFER];
		sprintf(nroBus,"%d",i);
		pid_t pid = fork();
		if (pid == 0) {
			execlp("./bus", "bus", nroBus, cantidadBuses, (char *) 0);
			sprintf(buffer, "Launcher Bus: Error: %s\n", strerror(errno));
			write(fileno(stderr), buffer, strlen(buffer));
		}
	}
	
	// Creando Puerta
	pid_t pid = fork();
	if (pid == 0) {
		execlp("./puerta", "puerta", (char *) 0);
		sprintf(buffer, "Launcher Puerta: Error: %s\n", strerror(errno));
		write(fileno(stderr), buffer, strlen(buffer));
	}

	// Creando Productor de personas
	static char cantidadPersonas[TAM_BUFFER];
	sprintf(cantidadPersonas, "%d",cantPersonas);
	pid = fork();
	if (pid == 0) {
		execlp("./productor", "productor", cantidadPersonas, (char *) 0);
		sprintf(buffer, "Launcher Productor: Error: %s\n", strerror(errno));
		write(fileno(stderr), buffer, strlen(buffer));
	}
	
	sprintf(buffer, "Launcher: Terminado \n");
	write(fileno(stdout), buffer, strlen(buffer));

	return 0;
}