Solución ejercicio 4

De Wiki de Sistemas Operativos
Saltar a: navegación, buscar
p1:
 for (int i=0; i<2; i++) { #1
     send(msg);            #2
     recv(msg);            #3
 }
P2:
 for (int i=0; i<2; i++) { #1
     recv(msg);            #2
     send(msg);            #3
 }
  /: bloqueado,  @: preparado, >: fin del programa, X: se ejecuta el planificador

       |i1=0   |i2=0   |       i1=1|   i2=1|           i1=2|i2=2|
       | #1| #2|   |   | #3|   | #1| #2|   |   | #3|   | #1|   |
P1     |---|---/   |   @---/   @---|---/   |   @---/   @--->   |
       |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
       |   |   | #1| #2|   | #3|   |   | #1| #2|   | #3|   | #1|
P2     |   |   |---|---/   @---/   |   @---|---/   @---/   |--->
planif X   |   X   |   X   X   X   X   X   |   X   X   X   X   X 
       |___|___|___|___|___|___|___|___|___|___|___|___|___|___|
       0   1   2   3   4   5   6   7   8   9   10  11  12  13  14


Otra posible solución:

    X = El proceso pasa a estado bloqueado.
    / = El proceso pasa a estado preparado.
    > = Fin de su ejecucion


    | #1| #2|   |   |   | #3| #1| #2|   |   |   | #3| #1|FIN|   |   |   |   |   |   |
  p1|---|---X   |   /   |---|---|---X   |   |   |---|--->   |   |   |   |   |   |   |
    |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
    |   |   | #1| #2| #3|   |   |   | #1| #2| #3|   |   | #1|FIN|   |   |   |   |   |
  p2|   |   |---|---|---X   /   |   |---|---|---X   /   |--->   |   |   |   |   |   |
    |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
    |___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
    0   1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16  17  18  19  20