Пример #1
0
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);
}
Пример #2
0
/*
* Hace el open del fichero que se usara como (sistema de archivos)
*/
int bmount (const char *camino) {
	fichero = open (camino, O_RDWR|O_CREAT, 0666);
	if (fichero == -1) {
		printf("Error al montar el sistema de ficheros.\n");
		return fichero;
	}
	iniciarSem(&semaforo); //Inicializamos el semaforo
	return fichero;
}
Пример #3
0
int bmount (const char *camino){
	int sem;
	iniciarSem(&sem);	//Inicia semáforo
	fichero = open(camino, O_RDWR|O_CREAT,0666); //Monta disco en R/W
	if(fichero == -1){
		printf("Error de apertura de archivo");
	}
	return fichero;
}