Ejecuta dos veces misma línea!! Hola, tengo una función un poco enrevesada, es recursiva, y hay un momento que ejecuta seguidas dos veces la misma línea! y es más la otra línea que marco, el printf, da error si lo pongo...
¿Qué sentido tiene eso?
La que me da error por ponerla es
printf("El tiempo3 va por: %f\n", tiempos_en_umbral[num_umbrales-1]);
Y la que ejecuta 2 veces es:
printf("El tiempo4 va por: %f\n", tiempos_en_umbral[num_umbrales-1]);
Están abajo del todo. Como auqnue sea una función recursiva, ejecuta 2 veces la misma línea? aunque haya varias llamdas pero debe ir una por una..
Código:
int ejecuta_muestra(float* periodo_MTBF, int contador_aciertos_fallos[2], float tiempos_reparandose_erlang[num_elementos], float tiempos_funcionando_weibull[num_elementos], float* MTBF, int* contadorfallosMTBF, int* primerMTBF, int primer_fallo, float* sumacuadradoMTTT, float* sumaMTTT, int transicion_pasada, float tiempos_en_umbral[num_umbrales], float hilos_indisponibilidad[1], int
printf("El tiempoPrimero va por: %f\n", tiempos_en_umbral[num_umbrales-1]);
int siguiente_acontecimiento, que_elemento, posicion,i, posicion_umbral, fallos;
float cantidad_a_reducir;
int copia_sistema_reparacion[tamanio_sistema_reparacion]; int ultimo_ha_descendido = 0;
int num_fallos = 0; int hilo_fallo = 0; int descenso_umbral = 0; int total_fallos = 0; int vuelta_hilo;
int fallos_antes = 0;int hasta_que_pos_umbral; float relojMTTT = 0;
int pintar, l;
vuelta_hilo = 0;
if (primera_ejecucion == 0)
/* siempre que este subprograma se ejecuta es por nuevo hilo, y hay que volcar el estado,
pero no si es la llamada inicial y es el hilo que viene de 0, ya viene inicializado desde fuera */
{
vuelca_estado(umbral_hilo, estado_int, estado_float, acontecimientos, sistema_reparacion, sistema, tasas_de_fallos, tiempos_funcionando_weibull, tiempos_reparandose_erlang);
intentos_restantes[umbral_hilo-1] = intentos_restantes[umbral_hilo -1]-1; /* saber cuantos faltan para cortar ultimo al ir descendiendo */
*funcionamiento_sistema = funcionamiento_sistema_[umbral_hilo -1]; reloj = reloj_[umbral_hilo -1];
if (primer_hilo == 0) {/* cambiar acontecimientos para que no se repita */
cambia_acontecimientos(sistema_reparacion, contador_aciertos_fallos, acontecimientos, tasas_de_fallos, tiempos_funcionando_weibull, tiempos_reparandose_erlang);
}
}
primera_ejecucion = 0; /* no ha volcado, ya siempre puede volcar el estado */
while ((vuelta_hilo == 0) && (reloj<duracion_muestra) && (descenso_umbral == 0))/* Condicion de parada de cada muestra */
{
siguiente_acontecimiento=primer_acontecimiento(acontecimientos, *funcionamiento_sistema); /* vemos que acontecimiento es el siguiente */
reloj = reloj + acontecimientos[siguiente_acontecimiento]; /* actualizamos el reloj */
cantidad_a_reducir = acontecimientos[siguiente_acontecimiento]; /* almacenamos la cantidad que debemos restar a todos los acontecimientos */
if (reloj < duracion_muestra) /* IMPORTANTE */
{/* Cuando queda poco para llegar a los 100, puede que el proximo acontecimiento se pase y no haya que contarlo */
fallos_antes = fallos_maximos(sistema);
/* Periodo transitorio */
if ((reloj > periodo_transitorio) && (transicion_pasada == 0)) /* importante, que sea la primera vez que entra */
{
transicion_pasada = 1; /* para que no siga entrando */
reloj = 0;
for (i=0;i<num_umbrales;i++) {tiempos_en_umbral[i] = 0;}
for(i=0;i<num_elementos;i++){tiempos_reparandose_erlang[i] = 0; tiempos_funcionando_weibull[i] = 0;}
}
/* Movimiento */
if (siguiente_acontecimiento < num_servidores) /* se produce salida de un servidor */
{
cir, *funcionamiento_sistema); /* se decrementan los acontecimientos */
acontecimientos[siguiente_acontecimiento] = INFINITO; /* se pone el servidor de momento a INFINITO */
(comprobar_funcionamiento(sistema, (que_elemento-1)) == 1)) /* si no funciona y con esa llegada se arregla el sistema */
{*funcionamiento_sistema = 1; *periodo_MTBF = reloj;} /* se pone a que funciona */
}
else /* se produce una llegada al sistema de reparacion */
{
primer_fallo = 1;
}
if (*primerMTBF == 1) {*primerMTBF = 0;}
else {
*contadorfallosMTBF = *contadorfallosMTBF +1; *MTBF = *MTBF + (reloj - *periodo_MTBF); *periodo_MTBF = reloj;
}
}
posicion = colocar_componente(sistema_reparacion, que_elemento); /* apilarle en el sistema de reparacion */
if (posicion < num_servidores) /* se ha colocado en un servidor */
{ tiempos_reparandose_erlang[que_elemento-1] = 0;
acontecimientos[posicion] = generar_aleatorio(contador_aciertos_fallos, 's', tasas_de_fallos, que_elemento, tiempos_funcionando_weibull, acontecimientos, tiempos_reparandose_erlang);}
if (!(sistema_reparacion[num_servidores+1] == 0)) /* si alemnos hay 2 componentesen la cola es necesario colocar por prioridades */
{colocar_cola_prioridades(sistema_reparacion, copia_sistema_reparacion, tasas_de_fallos, landas);}
}
/* caluclo tiempo por encima de umbrales */
total_fallos = fallos_maximos(sistema);
hasta_que_pos_umbral = hasta_que_umbral_afecta(fallos_antes, umbrales);
printf("El tiempo va por: %f\n", tiempos_en_umbral[num_umbrales-1]);
for (i=0;i<=hasta_que_pos_umbral;i++)
{ if (i== num_umbrales-1) {printf("Se le suma al tiempo en umbral final %f\n", cantidad_a_reducir);}
tiempos_en_umbral[i] = tiempos_en_umbral[i] + cantidad_a_reducir;
if (i== num_umbrales-1) {printf("El tiempo final va por %f\n", tiempos_en_umbral[i]);}
}
/* *** RESTART *** */
total_fallos = fallos_maximos(sistema);
if ((total_fallos < umbrales[umbral_hilo-1]) && !(umbral_hilo == 0))/* si se ha bajado del umbral */
{
if (ultimo_hilo == 0) /* si no es ultimo hilo se corta */
{descenso_umbral = 1;}
else {if ((ultimo_ha_descendido == 1) || (umbral_hilo == 1))/* es ultimo hilo y ya ha bajado o es el mas bajo*/
{ /* si el hilo es del primer umbral no puede bajar dos veces, es excepcion */
if (intentos_restantes[umbral_hilo -1] == 0) /* no quedan mas por atras */
{
umbral_hilo = umbral_hilo -1;
ultimo_ha_descendido = 0;
}
else{descenso_umbral = 1;} /* quedan por atras, debe cortarse */
}
else {ultimo_ha_descendido = 1; umbral_hilo = umbral_hilo -1;}
}
}
else
{
if (total_fallos == umbrales[umbral_hilo]) /* si alcanza un umbral superior */
{
if (umbral_hilo == (num_umbrales - 1)) /* umbral final */
{
if (hilo_fallo == 0)
{
hilo_fallo = 1;
num_fallos++;
}
}
else /* umbral intermedio */
{
ultimo_ha_descendido = 0;
umbral_hilo++;
intentos_restantes[umbral_hilo-1] = reintentos_umbrales[umbral_hilo -1]; /* se reponen */
captura_estado(umbral_hilo, estado_int, estado_float, acontecimientos, sistema_reparacion, sistema, tasas_de_fallos,
*funcionamiento_sistema, reloj, funcionamiento_sistema_, reloj_, tiempos_funcionando_weibull, tiempos_reparandose_erlang);
for (i=1;i<= reintentos_umbrales[umbral_hilo-1];i++)
{/* el umbral 1, esta en la pos 0, etc */
if (!(i == reintentos_umbrales[umbral_hilo-1])) {ultimo_hilo = 0;}
else {ultimo_hilo = 1; ultimo_ha_descendido = 0;}
printf("");
if (i==1) {primer_hilo = 1;}
else {primer_hilo = 0;}
num_fallos = num_fallos + ejecuta_muestra(periodo_MTBF, contador_aciertos_fallos, tiempos_reparandose_erlang, tiempos_funcionando_weibull, MTBF, contadorfallosMTBF, primerMTBF, primer_fallo, sumacuadradoMTTT, sumaMTTT, transicion_pasada, tiempos_en_umbral, hilos_indisponibilidad, ultimo_hilo, primera_ejecucion, intentos_restantes, primer_hilo, reloj,
umbral_hilo, funcionamiento_sistema, acontecimientos, sistema_reparacion, sistema,
tasas_de_fallos, landas, umbrales, reintentos_umbrales, funcionamiento_sistema_, reloj_, estado_float, estado_int);
vuelta_hilo = 1;
if (no_quedan_reintentos(intentos_restantes) == 1) {return(num_fallos);}
}
}
}
} /* fin restart */
}
/* printf("El tiempo3 va por: %f\n", tiempos_en_umbral[num_umbrales-1]); */
else {/* para que salga porque ese acontecimiento ya se pasaba */
if (*funcionamiento_sistema == 0) {hilos_indisponibilidad[0] = hilos_indisponibilidad[0]+1;
tiempos_en_umbral[num_umbrales-1] = tiempos_en_umbral[num_umbrales-1] + cantidad_a_reducir;}
}
printf("El tiempo4 va por: %f\n", tiempos_en_umbral[num_umbrales-1]);
} /* fin de la muestra */
return(num_fallos);
printf("El tiempo5 va por: %f\n", tiempos_en_umbral[num_umbrales-1]);
}
|