int main (int argc, char *argv[]) { pthread_t threads[NUM_THREADS]; int rc; long t; iniciarSem(&sem); //Inicia semáforo for(t=0; t<NUM_THREADS; t++){ rc = pthread_create(&threads[t], NULL, counter, (void *)t); if (rc){ printf("ERROR; return code from pthread_create() is %d\n", rc); exit(-1); } } for(t=0; t<NUM_THREADS; t++){ pthread_join(threads[t], NULL); } if(!sem){ obtenerSem(&sem); } eliminarSem(sem); //Finaliza semáforo float error = (MAX_COUNT-count)/(float) MAX_COUNT *100; printf("Final result: %ld Expected: %ld Error: %3.2f%%\n", count, MAX_COUNT, error); getrusage(RUSAGE_SELF, &usage); endu = usage.ru_utime; ends = usage.ru_stime; printf("Tiempo usuario: %ld s %ld ms \nTiempo sistema: %ld s %ld ms \n",endu.tv_sec, endu.tv_usec, ends.tv_sec, ends.tv_usec); pthread_exit(NULL); }
/* * Hace el close del fichero (sistema de archivos) */ int bumount() { if(close (fichero) == -1){ printf("Error al desmontar el sistema de ficheros.\n"); return -1; }else{ eliminarSem(semaforo); //Eliminamos el semaforo return 0; } }
int bumount(){ int sem; if(!sem){ obtenerSem(&sem); } eliminarSem(sem); //Finaliza semáforo if(close(fichero) < 0) //Desmonta disco printf("Error al cerrar de archivo"); return 1; return 0; }