-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathunit1.pas
163 lines (140 loc) · 4.92 KB
/
unit1.pas
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
(******************************************************************************)
(* CPU-Load ??.??.???? *)
(* *)
(* Version : 0.01 *)
(* *)
(* Author : Uwe Schächterle (Corpsman) *)
(* *)
(* Support : www.Corpsman.de *)
(* *)
(* Description : Application to create a multi threaded CPU-Load *)
(* *)
(* License : See the file license.md, located under: *)
(* https://github.com/PascalCorpsman/Software_Licenses/blob/main/license.md *)
(* for details about the license. *)
(* *)
(* It is not allowed to change or remove this text from any *)
(* source file of the project. *)
(* *)
(* Warranty : There is no warranty, neither in correctness of the *)
(* implementation, nor anything other that could happen *)
(* or go wrong, use at your own risk. *)
(* *)
(* Known Issues: none *)
(* *)
(* History : 0.01 - Initial version *)
(* *)
(******************************************************************************)
Unit Unit1;
{$MODE objfpc}{$H+}
Interface
Uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
Type
{ TForm1 }
TForm1 = Class(TForm)
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Procedure Button1Click(Sender: TObject);
Procedure Button2Click(Sender: TObject);
Procedure FormCloseQuery(Sender: TObject; Var CanClose: boolean);
Procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
End;
{ TLoadThread }
TLoadThread = Class(TThread)
private
fstartTime: int64;
fDelta: int64;
a: Array[0..1023] Of integer;
Procedure Register_Thread;
Procedure UnRegister_Thread;
public
Constructor create(Delta: integer); reintroduce;
Procedure Execute; override;
End;
Var
Form1: TForm1;
cnt: integer;
obj: TLoadThread;
Implementation
{$R *.lfm}
{ TLoadThread }
Constructor TLoadThread.create(Delta: integer);
Var
i: Integer;
Begin
Inherited create(false);
FreeOnTerminate := true;
fstartTime := GetTickCount64;
fDelta := Delta;
For i := 0 To high(a) Do
a[i] := i;
End;
Procedure TLoadThread.Execute;
Var
i: Integer;
Begin
Synchronize(@Register_Thread);
While fstartTime + 1000 * fDelta >= GetTickCount64 Do Begin
For i := 0 To high(a) Do Begin
a[(i + i * i) Mod length(a)] := ((a[(i + (i + 2) * i) Mod length(a)] + a[i]) Mod 65536) + 1;
End;
End;
Synchronize(@UnRegister_Thread);
End;
Procedure TLoadThread.Register_Thread;
Begin
inc(cnt);
form1.label4.caption := 'Aktive Threads : ' + inttostr(cnt);
End;
Procedure TLoadThread.UnRegister_Thread;
Begin
dec(cnt);
form1.label4.caption := 'Aktive Threads : ' + inttostr(cnt);
End;
{ TForm1 }
Procedure TForm1.FormCreate(Sender: TObject);
Begin
caption := 'CPU-Load ver. 0.01 by Corpsman';
edit1.text := '8';
edit2.text := '10';
label4.caption := 'Active threads : 0';
End;
Procedure TForm1.Button1Click(Sender: TObject);
Var
i, k: integer;
j: integer;
Begin
Button1.Enabled := false;
i := strtoint(edit1.text);
j := strtoint(edit2.text);
For k := 0 To i - 1 Do Begin
While (cnt >= 100) Do Begin
sleep(1);
End;
obj := TLoadThread.create(j);
End;
Button1.Enabled := true;
End;
Procedure TForm1.Button2Click(Sender: TObject);
Begin
close;
End;
Procedure TForm1.FormCloseQuery(Sender: TObject; Var CanClose: boolean);
Begin
canclose := cnt = 0;
If Not CanClose Then Begin
showmessage('Error closing only possible, if no impact thread is active.');
End;
End;
End.