-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathSpawnVsCreate.dpr
More file actions
42 lines (33 loc) · 864 Bytes
/
SpawnVsCreate.dpr
File metadata and controls
42 lines (33 loc) · 864 Bytes
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 SpawnVsCreate;
{$APPTYPE CONSOLE}
{$R *.res}
uses
{$I ../Impl.inc}
{$I ../Includes.inc}
System.SysUtils;
var
S1, S2: TSymmetric<string>;
Proc: TSymmetricRoutine<string>;
begin
Proc := procedure(const Name: string)
begin
try
while True do
begin
WriteLn(Format('Greenlet "%s" is called!', [Name]));
Yield;
end
finally
WriteLn(Format('Greenlet "%s" is terminated!', [Name]));
end
end;
S1 := TSymmetric<string>.Create(Proc, 'greenlet 1');
S2 := TSymmetric<string>.Spawn(Proc, 'greenlet 2');
Assert(IRawGreenlet(S1).GetState = gsReady);
Assert(IRawGreenlet(S2).GetState = gsExecute);
S2.Kill;
Assert(IRawGreenlet(S2).GetState = gsKilled);
IRawGreenlet(S1).Switch;
Assert(IRawGreenlet(S1).GetState = gsExecute);
ReadLn;
end.