{$mode objfpc}
uses sysutils, classes,
     u_test;

type
  tmythread = class(tthread)
  private
    msg: string;
    num: string;
    i: integer;
  protected
    procedure execute; override;
  public
    constructor create(s, n: string);
  end;

constructor tmythread.create(s, n: string);
begin
  i := 0;
  msg := s; num := n;
  inherited create(false);
end;

procedure tmythread.execute;
begin
  repeat
    Log.WaitToWrite;
    try
      Log.Write(num, msg);
    finally
      Log.done;
    end;
  until terminated;
end;


const n = 50;
var
  thrds: array[1 .. n] of TMyThread;
  i: integer;
begin
  for i := 1 to n do begin
    thrds[i] := TMyThread.Create('message #' + IntToStr(i), IntToStr(i));
  end;
  readln;
  for i := n downto 1 do begin
    thrds[i].Terminate;
  end;
  for i := n downto 1 do begin
    thrds[i].Destroy;
  end;
end.