unit uTestMultiHilo;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  umh_sincrodata;

type

  { TForm1 }

  TForm1 = class(TForm)
    btPasoCERO: TButton;
    btDarPaso: TButton;
    btTerminar: TButton;
    btInicicializarSincroData: TButton;
    procedure btPasoCEROClick(Sender: TObject);
    procedure btDarPasoClick(Sender: TObject);
    procedure btTerminarClick(Sender: TObject);
    procedure btInicicializarSincroDataClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;
var
  sincrodata_mh: TSinCroData_mh;
  k: integer;

implementation
{$R *.lfm}



{ TForm1 }

procedure TForm1.btPasoCEROClick(Sender: TObject);
begin
  sincrodata_mh.paso:= 0;
  sincrodata_mh.start_workers;
end;

procedure TForm1.btDarPasoClick(Sender: TObject);
begin
  // bien ahora comienza el trabajo.
  inc(  sincrodata_mh.Paso );
  sincrodata_mh.dst_HacerTareas( true, -1 );
  writeln('Esperado para continuar, terminé paso k: '+IntToStr( sincrodata_mh.Paso ) );
end;

procedure TForm1.btTerminarClick(Sender: TObject);
begin
    sincrodata_mh.Free;
    sincrodata_mh:= nil;
end;


procedure TForm1.btInicicializarSincroDataClick(Sender: TObject);
begin
  sincrodata_mh:= TSincrodata_mh.Create( 20, 4);
  for k:= 0 to high( sincrodata_mh.tareas ) do
    sincrodata_mh.tareas[k]:= TTarea_mh.Create( k );
  for k:= 0 to high( sincrodata_mh.robots ) do
    sincrodata_mh.robots[k]:= TWorker_mh.Create( k, sincrodata_mh );
end;


end.

