Ir para conteúdo
Fórum Script Brasil
  • 0

Como implementar o escalonamento FIFO no DELPHI?


Inforjo

Pergunta

Alguém tem uma idéia melhor para a ,implementação do FIFO em Delphi?

Consegui fazer o escalonamento de processo com um processo.

Mais pra dois da problema.

procedure TForm2.show(cor:Tcolor; tipo:string; tempo:integer);
begin
  inherited show;

   //vCor2[Form3.contador] :=  cor;
   vtempo[Form3.contador] := tempo;
   vtipo[Form3.contador] :=  tipo;

   inc(contadorAux);
   fila_aptos := TQueue.create;
   fila_aptos.Push(Tcor.create(cor)); //push coloca um item no final da fila
   atualiza_fila;
   if Form3.contador = 2 then
      if vtipo[contadorAux] =  'I/O Bound' then
      delay(tempo*3000*500*500*500*500)
       else
      delay(tempo*3000*500*500*500);
      inc(Form3.contador);

   try


   while Tcor(fila_aptos.Peek).valor <> clblack  do
        begin
           if contadorAux = 0 then
               exit;
             //Caso for I/O Bound
            if vtipo[contadorAux] =  'I/O Bound' then
              begin
                   pop :=  Tcor(fila_aptos.pop).valor;
                   //pop := vCor2[contadorAux];
                   delay(tempo*500);
                   IO.Brush.Color :=  pop;
                   if vCor2[contadorAux + 1] = clblack then
                     begin
                       s1.Visible := false;
                     end
                   else
                   if fila_aptos.Count <> 0 then
                     //atualiza_fila;
                     delay(tempo*3000);
                     IO.brush.color := clwhite;
                     CPU.brush.color := pop;
                     delay(tempo*500);
                     CPU.brush.color := clwhite;
                     IO.brush.color := pop;
                     delay(tempo*500);
                     IO.brush.color := clwhite;
                     CPU.brush.color := pop;
                     delay(tempo*500);
                     CPU.brush.color := clwhite;

                     //Finaliza processo
                     fin.Visible := true;
                     fin.brush.color := pop;
                     delay(tempo*500);
                     fin.Visible := false;
                     delay(tempo*500);
                     dec(contadorAux);
                     dec(Form3.contador);
              end
            else
              //Caso for CPU Bound
              begin
                    pop :=  Tcor(fila_aptos.pop).valor;
                    //pop := vCor2[contadorAux];
                   delay(tempo*500);
                   CPU.brush.color := pop;
                   if vCor2[contadorAux + 1] = clblack then
                     begin
                        s1.Visible := false;
                     end
                   else
                     if fila_aptos.Count <> 0 then
                     atualiza_fila;
                     delay(tempo*3000);
                     CPU.brush.color := clwhite;

                     //Finaliza Processo
                     fin.Visible := true;
                     fin.brush.color := pop;
                     delay(tempo*500);
                     fin.Visible := false;
                     delay(tempo*500);
                     dec(contadorAux);
                     dec(Form3.contador);

              end;
             if contadorAux = 0 then
                exit;
      end; //Fim do while
      finally
        fila_aptos.free;
    end; //fim do try

end;

procedure TForm2.Timer1Timer(Sender: TObject);
begin
   label16.Caption  := inttostr(i);
   if odd(i) then
        shape3.Visible := true
   else
        shape3.Visible := false;
   inc(i);
end;

procedure TForm2.Bt2Click(Sender: TObject);
begin
     status := 'true';
end;

//TIME SLACE ou FATIA DE TEMPO
procedure TForm2.Delay(MSec: Cardinal);
  var Start: Cardinal;
begin
  Start := GetTickCount;
  repeat
     Application.ProcessMessages;
  until (GetTickCount - Start) >= MSec;
end;

procedure TForm2.Bt3Click(Sender: TObject);
begin
close;
end;

procedure TForm2.Bt1Click(Sender: TObject);
begin

Form3.show('FIFO');

if Form3.contador < 10  then
 form3.visible := true
else showmessage('Limite de processos');
end;

//ordena os processos na fila
procedure TForm2.atualiza_fila;
var px:integer;
begin
   for px:=1 to contadorAux do
                     begin
                        if contadorAux = 0 then
                            exit;
                       if  contadorAux = 1 then
                         begin
                           s1.brush.color :=  Tcor(fila_aptos.Peek).valor;
                           s1.visible := true;
                         end;
                        if  contadorAux = 2 then
                           begin
                           s2.brush.color :=  Tcor(fila_aptos.Peek).valor;
                           s2.visible := true;
                           end;
                        if  contadorAux = 3 then
                           begin
                           s3.brush.color :=  Tcor(fila_aptos.Peek).valor;
                           s3.visible := true;
                           end;
                        if  contadorAux = 4 then
                           begin
                           s4.brush.color :=  Tcor(fila_aptos.Peek).valor;
                           s4.visible := true;
                           end;
                        if  contadorAux= 5 then
                           begin
                           s5.brush.color :=  Tcor(fila_aptos.Peek).valor;
                           s5.visible := true;
                           end;
                        if  contadorAux = 6 then
                           begin
                           s6.brush.color :=  Tcor(fila_aptos.Peek).valor;
                           s6.visible := true;
                           end;
                        if  contadorAux = 7 then
                           begin
                           s7.brush.color :=  Tcor(fila_aptos.Peek).valor;
                           s7.visible := true;
                           end;
                        if  contadorAux = 8 then
                           begin
                           s8.brush.color := Tcor(fila_aptos.Peek).valor;
                           s8.visible := true;
                           end;
                        if  contadorAux = 9 then
                           begin
                           s9.brush.color :=  Tcor(fila_aptos.Peek).valor;
                           s9.visible := true;
                           end;

                       if  status = 'true' then
                            exit;
                        if contadorAux = 0 then
                            exit;
                        end;

end;

//Fatia de tempo do objeto Trackbar 
function TForm2.timeslice(ts: integer): integer;
begin

    if TrackBar1.Position = 0 then
     ts := 2000;
    if TrackBar1.Position = 1 then
     ts := 1000;
    if TrackBar1.Position = 2 then
     ts := 800;
    if TrackBar1.Position = 3 then
     ts := 500;
    if TrackBar1.Position = 4 then
     ts := 400;
    if TrackBar1.Position = 5 then
     ts := 300;
    if TrackBar1.Position = 6 then
     ts := 200;
    if TrackBar1.Position = 7 then
     ts := 100;
    if TrackBar1.Position = 8 then
     ts := 75;
    if TrackBar1.Position = 9 then
     ts := 60;
    if TrackBar1.Position = 10 then
    ts := 30;
   Result := ts;
end;

Mais detalhes baixe o simulador em:

http://br.groups.yahoo.com/group/inforjo/f...DSO%20-%202010/

ou

http://br.groups.yahoo.com/group/inforjo/

Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      651,9k
×
×
  • Criar Novo...