int main (int argc, char *argv[]) { bool control = false; if(argc>1) { control = true; } std::cout << control; pthread_t th1, th2, th3, th4, th5; pthread_create(&th1, NULL, &servicioSuma, NULL); pthread_create(&th2, NULL, &comunicacion, NULL); sleep(2); if(control) { SocketDatagrama socket; socket.activaBroadcast(); sem_init(&mutex1, 0, 1); sem_init(&mutex2, 0, 0); pthread_create(&th3, NULL, &broadcast, &socket); pthread_create(&th4, NULL, &ordenamientoImpresion, NULL); pthread_create(&th5, NULL, &recepcion, &socket); pthread_join(th3, NULL); pthread_join(th4, NULL); pthread_join(th5, NULL); } pthread_join(th1, NULL); pthread_join(th2, NULL); exit(0); }
int main(void){ pthread_t th1, th2, th3; SocketDatagrama socket; socket.activaBroadcast(); // Inicializa los semaforos sem_init(&mutex1, 0, 1); sem_init(&mutex2, 0, 0); // Crea hilos pthread_create(&th1, NULL, &broadcast, &socket); pthread_create(&th2, NULL, &ordenamientoImpresion, NULL); pthread_create(&th3, NULL, &recepcion, &socket); // Esperar a que los hilos terminen pthread_join(th1, NULL); pthread_join(th2, NULL); pthread_join(th3, NULL); exit(0); }