bansi1mt.pp 734 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. {$i bansi1.inc}
  2. var
  3. NumThreads: Integer = 4;
  4. type
  5. TBenchThread = class(TThread)
  6. public
  7. procedure Execute; override;
  8. end;
  9. procedure TBenchThread.Execute;
  10. begin
  11. Benchmark;
  12. end;
  13. var
  14. threads: array of TBenchThread;
  15. I: integer;
  16. begin
  17. if ParamCount > 0 then
  18. begin
  19. NumThreads := StrToIntDef(ParamStr(1), 0);
  20. if NumThreads < 1 then
  21. begin
  22. writeln('Pass a valid number of threads, >= 1');
  23. exit;
  24. end;
  25. end;
  26. { main thread is also a thread }
  27. setlength(threads, NumThreads-1);
  28. for I := low(threads) to high(threads) do
  29. threads[I] := TBenchThread.Create(false);
  30. Benchmark;
  31. for I := low(threads) to high(threads) do
  32. begin
  33. threads[I].waitfor;
  34. threads[I].free;
  35. end;
  36. end.