-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathScheduling.dpr
More file actions
53 lines (41 loc) · 1.19 KB
/
Scheduling.dpr
File metadata and controls
53 lines (41 loc) · 1.19 KB
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
43
44
45
46
47
48
49
50
51
52
53
program Scheduling;
{$APPTYPE CONSOLE}
{$R *.res}
uses
{$I ../Impl.inc}
{$I ../Includes.inc}
Classes,
System.SysUtils;
function Fibonacci(N: Integer): Integer;
begin
if N < 0 then
raise Exception.Create('The Fibonacci sequence is not defined for negative integers.');
case N of
0: Result:= 0;
1: Result:= 1;
else
Result := Fibonacci(N - 1) + Fibonacci(N - 2);
end;
end;
function ThreadedFibo(const N: Integer): string;
begin
Result := Format('Thread %d. Fibonacci(%d) = %d',
[TThread.CurrentThread.ThreadID, N, Fibonacci(N)])
end;
var
F1, F2, F3: TAsymmetric<string>;
OtherThread: TGreenThread;
begin
OtherThread := TGreenThread.Create;
try
F1 := OtherThread.Asymmetrics<string>.Spawn<Integer>(ThreadedFibo, 10);
F2 := OtherThread.Asymmetrics<string>.Spawn<Integer>(ThreadedFibo, 20);
F3 := OtherThread.Asymmetrics<string>.Spawn<Integer>(ThreadedFibo, 30);
Writeln(Format('F1.GetResult = "%s"', [F1.GetResult]));
Writeln(Format('F2.GetResult = "%s"', [F2.GetResult]));
Writeln(Format('F3.GetResult = "%s"', [F3.GetResult]));
Readln;
finally
OtherThread.Free
end;
end.