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