Diferencia entre revisiones de «Solución ejercicio 7»

De Wiki de Sistemas Operativos
Saltar a: navegación, buscar
Línea 2: Línea 2:
 
<source lang="c">
 
<source lang="c">
 
for (int i = 0; i<2; i++){ //#1
 
for (int i = 0; i<2; i++){ //#1
      down(s) ;           //#2
+
  while(cerrojo_p2);     //#2
       f();                //#3
+
      cerrojo_p1 = 1;      //#3
       up(s);               //#4
+
       f();                //#4
 
+
       cerrojo_p1 = 0;     //#5
 +
 
}
 
}
 
</source>
 
</source>
Línea 13: Línea 14:
 
<source lang="c">
 
<source lang="c">
 
for (int i = 0; i<2; i++){ //#1
 
for (int i = 0; i<2; i++){ //#1
      down(s) ;           //#2
+
  while(cerrojo_p1);     //#2
       f();                //#3
+
      cerrojo_p2 = 1;      //#3
       up(s);               //#4
+
       f();                //#4
 
+
       cerrojo_p2 = 0;     //#5
 +
 
}
 
}
 
</source>
 
</source>
       X = El proceso pasa a estado bloqueado.
+
        
      / = El proceso pasa a estado preparado.
 
 
       > = Fin de su ejecucion
 
       > = Fin de su ejecucion
 
   
 
   
 
   
 
   
       | #1| #2| #3|  |  | #4| #1| #2|  |  |  | #3| #4| #1|  |   |   |  |  |  |
+
       > = Fin de su ejecucion
    h1|---|---|---|  |  |---|---|---X   |  /   |---|---|--->  |  |  |  |  |  |
+
 
      |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
+
 
      |  |  |  | #1| #2|  |  |  | #3| #4| #1|  |  |  | #2| #3| #4| #1|  |  |
+
    | #1| #2| #3|  |  | #4| #5| #1|  |  |  | #2| #2| #2|  |  |  | #2| #3| #4|  |  |  | #5| #1|  |
    h2|  |  |  |---|---X   /   |  |---|---|---|  |  |  |---|---|------->  |  |
+
  h1|---|---|---|  |  |  |---|---|---|  |  |---|---|---|   |  |   |---|---|---|  |  |  |---|--->   |
      |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
+
    |   |  |  |  |  |  |   |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
      |___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
+
    |  |  |  | #1| #2| #2|  |  |  | #2| #3| #4|  |  |  | #5| #1| #2|  |  |  | #3| #4| #5|  |  | #1|
      0  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20
+
  h2|  |  |  |---|---|---|   |   |  |---|---|---|  |  |  |---|---|---|  |  |  |---|---|---|  |  |--->
 +
    |   |  |   |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
 +
    |___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
 +
    0  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20 21  22  23  24  25  26  27
 +
 
 +
    Nota: La solución que estaba antes propuesta no tenia relación con el ejercicio 7.Esta solucion todavía no ha sido revisada por Pablo.

Revisión del 12:18 6 dic 2011

Hilo h1

for (int i = 0; i<2; i++){ //#1
   while(cerrojo_p2);      //#2
      cerrojo_p1 = 1;      //#3
      f();                 //#4
      cerrojo_p1 = 0;      //#5
 
}

Hilo h2

for (int i = 0; i<2; i++){ //#1
   while(cerrojo_p1);      //#2
      cerrojo_p2 = 1;      //#3
      f();                 //#4
      cerrojo_p2 = 0;      //#5
 
}
     > = Fin de su ejecucion


     > = Fin de su ejecucion


    | #1| #2| #3|   |   |   | #4| #5| #1|   |   |   | #2| #2| #2|   |   |   | #2| #3| #4|   |   |   | #5| #1|   |
  h1|---|---|---|   |   |   |---|---|---|   |   |   |---|---|---|   |   |   |---|---|---|   |   |   |---|--->   |
    |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
    |   |   |   | #1| #2| #2|   |   |   | #2| #3| #4|   |   |   | #5| #1| #2|   |   |   | #3| #4| #5|   |   | #1|
  h2|   |   |   |---|---|---|   |   |   |---|---|---|   |   |   |---|---|---|   |   |   |---|---|---|   |   |--->
    |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
    |___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
    0   1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27
    Nota: La solución que estaba antes propuesta no tenia relación con el ejercicio 7.Esta solucion todavía no ha sido revisada por Pablo.