Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program ej13
- var
- estadoCPU0:integer;
- estadoCPU1:integer;
- contCPU0:integer;
- contCPU1:integer;
- pidCPU0:integer;
- pidCPU1:integer;
- process asignarCPU;
- begin
- while true do
- begin
- receive(avisa, i); //se queda esperando a que un proceso lo despierte
- receive(mutex,msg);
- if (estadoCPU0 = true) then
- begin
- estadoCPU0:= false //Le asigno el proceo al CPU0
- pidCPU0:= i;
- contCPU0:= contCPU0 + 1;
- send(permiso,null);
- end
- else
- if (estadoCPU1 = true) then
- begin
- estadoCPU1:= false; {asigno CPU1 al proceso}
- pidCPU1:= i;
- contCPU1:= contCPU1 + 1;
- send(permiso,null);
- end;
- end;
- send(mutex,null);
- end;
- process type proceso (i:integer);
- var
- msg: message;
- begin
- if (estadoCPU0 = false) and (estadoCPU1 = false) then
- receive(colaProceso,msg);
- send(avisa,i); //aviso que solicito CPU
- receive(permiso,msg); //El proceso se queda esperando a que se le asigne una CPU.
- writeln ('realizo proceso : ', i);
- if (pidCPU0 = i) then
- estadoCPU0:= true
- else
- estadoCPU1:= true
- send(colaProceso,null);
- end;
- procedure informar;
- begin
- writeln('Asignaciones CPU 0: ', contCPU0);
- writeln('Asignaciones CPU 1: ', contCPU1);
- end;
- var
- colaProceso:mailbox;
- avisa:mailbox;
- permiso:mailbox;
- mutex:mailbox;
- aProcesos:array[1..N] of proceso
- i:integer;
- begin
- send(mutex,null);
- estadoCPU0:= true; //Libre
- estadoCPU1:= true;
- contCPU0:= 0;
- contCPU1:= 0;
- cobegin
- for i:= 1 to N do
- aProcesos[i](i);
- asignarCPU;
- coend;
- informar();
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement