bansi1mt.pp 769 B

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