Advertisement
Guest User

ej13

a guest
Jun 23rd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.54 KB | None | 0 0
  1. program ej13
  2.  
  3. var
  4. estadoCPU0:integer;
  5. estadoCPU1:integer;
  6. contCPU0:integer;
  7. contCPU1:integer;
  8. pidCPU0:integer;
  9. pidCPU1:integer;
  10.  
  11. process asignarCPU;
  12. begin
  13.     while true do
  14.         begin
  15.         receive(avisa, i); //se queda esperando a que un proceso lo despierte
  16.  
  17.         receive(mutex,msg);
  18.         if (estadoCPU0 = true) then
  19.             begin
  20.             estadoCPU0:= false //Le asigno el proceo al CPU0
  21.             pidCPU0:= i;
  22.             contCPU0:= contCPU0 + 1;
  23.             send(permiso,null);
  24.             end
  25.         else
  26.             if (estadoCPU1 = true) then
  27.                 begin
  28.                 estadoCPU1:= false; {asigno CPU1 al proceso}
  29.                 pidCPU1:= i;
  30.                 contCPU1:= contCPU1 + 1;
  31.                 send(permiso,null);
  32.                 end;
  33.         end;
  34.         send(mutex,null);
  35. end;
  36.  
  37.  
  38. process type proceso (i:integer);
  39. var
  40. msg: message;
  41. begin
  42.  
  43.     if (estadoCPU0 = false) and (estadoCPU1 = false) then
  44.         receive(colaProceso,msg);
  45.  
  46.     send(avisa,i); //aviso que solicito CPU
  47.     receive(permiso,msg); //El proceso se queda esperando a que se le asigne una CPU.
  48.  
  49.     writeln ('realizo proceso : ', i);
  50.  
  51.  
  52.     if (pidCPU0 = i) then
  53.         estadoCPU0:= true
  54.     else
  55.         estadoCPU1:= true
  56.     send(colaProceso,null);
  57.  
  58. end;
  59.  
  60.  
  61. procedure informar;
  62. begin
  63.     writeln('Asignaciones CPU 0: ', contCPU0);
  64.     writeln('Asignaciones CPU 1: ', contCPU1);
  65. end;
  66.  
  67. var
  68. colaProceso:mailbox;
  69. avisa:mailbox;
  70. permiso:mailbox;
  71. mutex:mailbox;
  72.  
  73. aProcesos:array[1..N] of proceso
  74. i:integer;
  75. begin
  76.     send(mutex,null);
  77.     estadoCPU0:= true; //Libre
  78.     estadoCPU1:= true;
  79.     contCPU0:= 0;
  80.     contCPU1:= 0;
  81.  
  82.     cobegin
  83.             for i:= 1 to N do
  84.                 aProcesos[i](i);
  85.             asignarCPU;
  86.     coend;
  87.     informar();
  88. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement