mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-06 18:58:12 +02:00
examples: fixed multithreading examples compilation with trunk FPC (2.5.1). Patch from alexs.
git-svn-id: trunk@24054 -
This commit is contained in:
parent
66978feef5
commit
6ec276af67
@ -1,14 +1,18 @@
|
||||
<?xml version="1.0"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<PathDelim Value="/"/>
|
||||
<Version Value="6"/>
|
||||
<Version Value="7"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<LRSInOutputDirectory Value="False"/>
|
||||
</Flags>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<MainUnit Value="0"/>
|
||||
<IconPath Value="./"/>
|
||||
<TargetFileExt Value=""/>
|
||||
</General>
|
||||
<VersionInfo>
|
||||
<StringTable Comments="" CompanyName="" FileDescription="" FileVersion="0.0.0.0" InternalName="" LegalCopyright="" LegalTrademarks="" OriginalFilename="" ProductName="" ProductVersion="0.0.0.0"/>
|
||||
</VersionInfo>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<IgnoreBinaries Value="False"/>
|
||||
@ -34,9 +38,9 @@
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="criticalsectionunit1.pas"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ResourceFilename Value="criticalsectionunit1.lrs"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="CriticalSectionUnit1"/>
|
||||
</Unit1>
|
||||
</Units>
|
||||
|
@ -1,43 +1,43 @@
|
||||
object Form1: TForm1
|
||||
Caption = 'Form1'
|
||||
ClientHeight = 169
|
||||
ClientWidth = 312
|
||||
PixelsPerInch = 75
|
||||
HorzScrollBar.Page = 311
|
||||
VertScrollBar.Page = 168
|
||||
Left = 286
|
||||
Height = 169
|
||||
Top = 202
|
||||
Width = 312
|
||||
HorzScrollBar.Page = 311
|
||||
VertScrollBar.Page = 168
|
||||
ActiveControl = CountWithCritSecButton
|
||||
Caption = 'Form1'
|
||||
ClientHeight = 169
|
||||
ClientWidth = 312
|
||||
LCLVersion = '0.9.29'
|
||||
object Label1: TLabel
|
||||
Caption = 'Label1'
|
||||
Color = clNone
|
||||
ParentColor = False
|
||||
Left = 43
|
||||
Height = 17
|
||||
Height = 18
|
||||
Top = 125
|
||||
Width = 65
|
||||
Width = 46
|
||||
Caption = 'Label1'
|
||||
ParentColor = False
|
||||
end
|
||||
object CountWithCritSecButton: TButton
|
||||
Left = 40
|
||||
Height = 37
|
||||
Top = 24
|
||||
Width = 196
|
||||
AutoSize = True
|
||||
BorderSpacing.InnerBorder = 4
|
||||
Caption = 'Count with critical section'
|
||||
OnClick = CountWithCritSecButtonClick
|
||||
TabOrder = 0
|
||||
Left = 40
|
||||
Height = 26
|
||||
Top = 24
|
||||
Width = 158
|
||||
end
|
||||
object CountWithoutCritSecButton: TButton
|
||||
Left = 40
|
||||
Height = 37
|
||||
Top = 64
|
||||
Width = 219
|
||||
AutoSize = True
|
||||
BorderSpacing.InnerBorder = 4
|
||||
Caption = 'Count without critical section'
|
||||
OnClick = CountWithoutCritSecButtonClick
|
||||
TabOrder = 1
|
||||
Left = 40
|
||||
Height = 26
|
||||
Top = 64
|
||||
Width = 175
|
||||
end
|
||||
end
|
||||
|
@ -1,16 +1,17 @@
|
||||
{ Dies ist eine automatisch erzeugte Lazarus-Ressourcendatei }
|
||||
{ This is an automatically generated lazarus resource file }
|
||||
|
||||
LazarusResources.Add('TForm1','FORMDATA',[
|
||||
'TPF0'#6'TForm1'#5'Form1'#7'Caption'#6#5'Form1'#12'ClientHeight'#3#169#0#11'C'
|
||||
+'lientWidth'#3'8'#1#13'PixelsPerInch'#2'K'#18'HorzScrollBar.Page'#3'7'#1#18
|
||||
+'VertScrollBar.Page'#3#168#0#4'Left'#3#30#1#6'Height'#3#169#0#3'Top'#3#202#0
|
||||
+#5'Width'#3'8'#1#0#6'TLabel'#6'Label1'#7'Caption'#6#6'Label1'#5'Color'#7#6'c'
|
||||
+'lNone'#11'ParentColor'#8#4'Left'#2'+'#6'Height'#2#17#3'Top'#2'}'#5'Width'#2
|
||||
+'A'#0#0#7'TButton'#22'CountWithCritSecButton'#8'AutoSize'#9#25'BorderSpacing'
|
||||
+'.InnerBorder'#2#4#7'Caption'#6#27'Count with critical section'#7'OnClick'#7
|
||||
+#27'CountWithCritSecButtonClick'#8'TabOrder'#2#0#4'Left'#2'('#6'Height'#2#26
|
||||
+#3'Top'#2#24#5'Width'#3#158#0#0#0#7'TButton'#25'CountWithoutCritSecButton'#8
|
||||
+'AutoSize'#9#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#30'Count without'
|
||||
+' critical section'#7'OnClick'#7#30'CountWithoutCritSecButtonClick'#8'TabOrd'
|
||||
+'er'#2#1#4'Left'#2'('#6'Height'#2#26#3'Top'#2'@'#5'Width'#3#175#0#0#0#0
|
||||
'TPF0'#6'TForm1'#5'Form1'#4'Left'#3#30#1#6'Height'#3#169#0#3'Top'#3#202#0#5'W'
|
||||
+'idth'#3'8'#1#18'HorzScrollBar.Page'#3'7'#1#18'VertScrollBar.Page'#3#168#0#13
|
||||
+'ActiveControl'#7#22'CountWithCritSecButton'#7'Caption'#6#5'Form1'#12'Client'
|
||||
+'Height'#3#169#0#11'ClientWidth'#3'8'#1#10'LCLVersion'#6#6'0.9.29'#0#6'TLabe'
|
||||
+'l'#6'Label1'#4'Left'#2'+'#6'Height'#2#18#3'Top'#2'}'#5'Width'#2'.'#7'Captio'
|
||||
+'n'#6#6'Label1'#11'ParentColor'#8#0#0#7'TButton'#22'CountWithCritSecButton'#4
|
||||
+'Left'#2'('#6'Height'#2'%'#3'Top'#2#24#5'Width'#3#196#0#8'AutoSize'#9#25'Bor'
|
||||
+'derSpacing.InnerBorder'#2#4#7'Caption'#6#27'Count with critical section'#7
|
||||
+'OnClick'#7#27'CountWithCritSecButtonClick'#8'TabOrder'#2#0#0#0#7'TButton'#25
|
||||
+'CountWithoutCritSecButton'#4'Left'#2'('#6'Height'#2'%'#3'Top'#2'@'#5'Width'
|
||||
+#3#219#0#8'AutoSize'#9#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#30'Cou'
|
||||
+'nt without critical section'#7'OnClick'#7#30'CountWithoutCritSecButtonClick'
|
||||
+#8'TabOrder'#2#1#0#0#0
|
||||
]);
|
||||
|
@ -41,9 +41,11 @@ type
|
||||
{ TMyThread }
|
||||
|
||||
TMyThread = class(TThread)
|
||||
private
|
||||
FAFinished: boolean;
|
||||
public
|
||||
procedure Execute; override;
|
||||
property Finished: boolean read FFinished write FFinished;
|
||||
property AFinished: boolean read FAFinished write FAFinished;
|
||||
end;
|
||||
|
||||
{ TForm1 }
|
||||
@ -99,7 +101,7 @@ begin
|
||||
repeat
|
||||
AllFinished:=true;
|
||||
for i:=Low(Threads) to High(Threads) do
|
||||
if not Threads[i].Finished then AllFinished:=false;
|
||||
if not Threads[i].AFinished then AllFinished:=false;
|
||||
until AllFinished;
|
||||
// free the threads
|
||||
for i:=Low(Threads) to High(Threads) do
|
||||
@ -120,6 +122,7 @@ var
|
||||
CurCounter: LongInt;
|
||||
j: Integer;
|
||||
begin
|
||||
FAFinished:=false;
|
||||
// increment the counter many times
|
||||
// Because the other threads are doing the same, it will frequently happen,
|
||||
// that 2 (or more) threads read the same number, increment it by one and
|
||||
@ -137,7 +140,7 @@ begin
|
||||
LeaveCriticalSection(Form1.CriticalSection);
|
||||
end;
|
||||
end;
|
||||
Finished:=true;
|
||||
FAFinished:=true;
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
@ -1,14 +1,18 @@
|
||||
<?xml version="1.0"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<PathDelim Value="/"/>
|
||||
<Version Value="6"/>
|
||||
<Version Value="7"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<LRSInOutputDirectory Value="False"/>
|
||||
</Flags>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<MainUnit Value="0"/>
|
||||
<IconPath Value="./"/>
|
||||
<TargetFileExt Value=""/>
|
||||
</General>
|
||||
<VersionInfo>
|
||||
<StringTable Comments="" CompanyName="" FileDescription="" FileVersion="0.0.0.0" InternalName="" LegalCopyright="" LegalTrademarks="" OriginalFilename="" ProductName="" ProductVersion="0.0.0.0"/>
|
||||
</VersionInfo>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||
@ -33,9 +37,9 @@
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="mainunit.pas"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ResourceFilename Value="mainunit.lrs"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="MainUnit"/>
|
||||
</Unit1>
|
||||
</Units>
|
||||
|
@ -1,34 +1,36 @@
|
||||
object Form1: TForm1
|
||||
Caption = 'Form1'
|
||||
ClientHeight = 142
|
||||
ClientWidth = 303
|
||||
OnCreate = FormCreate
|
||||
PixelsPerInch = 75
|
||||
HorzScrollBar.Page = 302
|
||||
VertScrollBar.Page = 141
|
||||
Left = 286
|
||||
Height = 142
|
||||
Top = 202
|
||||
Width = 303
|
||||
HorzScrollBar.Page = 302
|
||||
VertScrollBar.Page = 141
|
||||
ActiveControl = StartStopButton
|
||||
Caption = 'Form1'
|
||||
ClientHeight = 142
|
||||
ClientWidth = 303
|
||||
OnCreate = FormCreate
|
||||
LCLVersion = '0.9.29'
|
||||
object StartStopButton: TButton
|
||||
Left = 72
|
||||
Height = 25
|
||||
Top = 40
|
||||
Width = 158
|
||||
Anchors = [akTop]
|
||||
BorderSpacing.InnerBorder = 4
|
||||
Caption = 'Start'
|
||||
OnClick = StartStopButtonClick
|
||||
TabOrder = 0
|
||||
Left = 72
|
||||
Height = 25
|
||||
Top = 40
|
||||
Width = 158
|
||||
end
|
||||
object ProgressBar1: TProgressBar
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
Max = 1000
|
||||
Smooth = True
|
||||
Step = 1
|
||||
Left = 32
|
||||
Height = 20
|
||||
Top = 88
|
||||
Width = 244
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
Max = 1000
|
||||
Smooth = True
|
||||
Step = 1
|
||||
TabOrder = 1
|
||||
end
|
||||
end
|
||||
|
@ -1,14 +1,14 @@
|
||||
{ Dies ist eine automatisch erzeugte Lazarus-Ressourcendatei }
|
||||
{ This is an automatically generated lazarus resource file }
|
||||
|
||||
LazarusResources.Add('TForm1','FORMDATA',[
|
||||
'TPF0'#6'TForm1'#5'Form1'#7'Caption'#6#5'Form1'#12'ClientHeight'#3#142#0#11'C'
|
||||
+'lientWidth'#3'/'#1#8'OnCreate'#7#10'FormCreate'#13'PixelsPerInch'#2'K'#18'H'
|
||||
+'orzScrollBar.Page'#3'.'#1#18'VertScrollBar.Page'#3#141#0#4'Left'#3#30#1#6'H'
|
||||
+'eight'#3#142#0#3'Top'#3#202#0#5'Width'#3'/'#1#0#7'TButton'#15'StartStopButt'
|
||||
+'on'#7'Anchors'#11#5'akTop'#0#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6
|
||||
+#5'Start'#7'OnClick'#7#20'StartStopButtonClick'#8'TabOrder'#2#0#4'Left'#2'H'
|
||||
+#6'Height'#2#25#3'Top'#2'('#5'Width'#3#158#0#0#0#12'TProgressBar'#12'Progres'
|
||||
+'sBar1'#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#3'Max'#3#232#3#6'Smoot'
|
||||
+'h'#9#4'Step'#2#1#4'Left'#2' '#6'Height'#2#20#3'Top'#2'X'#5'Width'#3#244#0#0
|
||||
+#0#0
|
||||
'TPF0'#6'TForm1'#5'Form1'#4'Left'#3#30#1#6'Height'#3#142#0#3'Top'#3#202#0#5'W'
|
||||
+'idth'#3'/'#1#18'HorzScrollBar.Page'#3'.'#1#18'VertScrollBar.Page'#3#141#0#13
|
||||
+'ActiveControl'#7#15'StartStopButton'#7'Caption'#6#5'Form1'#12'ClientHeight'
|
||||
+#3#142#0#11'ClientWidth'#3'/'#1#8'OnCreate'#7#10'FormCreate'#10'LCLVersion'#6
|
||||
+#6'0.9.29'#0#7'TButton'#15'StartStopButton'#4'Left'#2'H'#6'Height'#2#25#3'To'
|
||||
+'p'#2'('#5'Width'#3#158#0#7'Anchors'#11#5'akTop'#0#25'BorderSpacing.InnerBor'
|
||||
+'der'#2#4#7'Caption'#6#5'Start'#7'OnClick'#7#20'StartStopButtonClick'#8'TabO'
|
||||
+'rder'#2#0#0#0#12'TProgressBar'#12'ProgressBar1'#4'Left'#2' '#6'Height'#2#20
|
||||
+#3'Top'#2'X'#5'Width'#3#244#0#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#3
|
||||
+'Max'#3#232#3#6'Smooth'#9#4'Step'#2#1#8'TabOrder'#2#1#0#0#0
|
||||
]);
|
||||
|
@ -29,7 +29,7 @@ interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Buttons,
|
||||
ComCtrls, FileUtil;
|
||||
ComCtrls, FileUtil, StdCtrls;
|
||||
|
||||
type
|
||||
|
||||
@ -85,7 +85,8 @@ begin
|
||||
fs:=TFileStream.Create(UTF8ToSys(Filename),fmOpenRead);
|
||||
try
|
||||
SetLength(Buffer,10);
|
||||
while true do begin
|
||||
while true do
|
||||
begin
|
||||
|
||||
// process all user events, like clicking on the button
|
||||
Application.ProcessMessages;
|
||||
@ -96,7 +97,8 @@ begin
|
||||
if Count=0 then break;
|
||||
|
||||
// process ...
|
||||
for i:=1 to Count do begin
|
||||
for i:=1 to Count do
|
||||
begin
|
||||
Last:=Now;
|
||||
repeat
|
||||
until Now-Last>(double(1)/fs.Size)/10000;
|
||||
|
@ -1,14 +1,18 @@
|
||||
<?xml version="1.0"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<PathDelim Value="/"/>
|
||||
<Version Value="6"/>
|
||||
<Version Value="7"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<LRSInOutputDirectory Value="False"/>
|
||||
</Flags>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<MainUnit Value="0"/>
|
||||
<IconPath Value="./"/>
|
||||
<TargetFileExt Value=""/>
|
||||
</General>
|
||||
<VersionInfo>
|
||||
<StringTable Comments="" CompanyName="" FileDescription="" FileVersion="0.0.0.0" InternalName="" LegalCopyright="" LegalTrademarks="" OriginalFilename="" ProductName="" ProductVersion="0.0.0.0"/>
|
||||
</VersionInfo>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<IgnoreBinaries Value="False"/>
|
||||
@ -34,9 +38,9 @@
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="processmessagesunit1.pas"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ResourceFilename Value="processmessagesunit1.lrs"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="ProcessMessagesUnit1"/>
|
||||
</Unit1>
|
||||
</Units>
|
||||
|
@ -1,14 +1,18 @@
|
||||
<?xml version="1.0"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<PathDelim Value="/"/>
|
||||
<Version Value="6"/>
|
||||
<Version Value="7"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<LRSInOutputDirectory Value="False"/>
|
||||
</Flags>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<MainUnit Value="0"/>
|
||||
<IconPath Value="./"/>
|
||||
<TargetFileExt Value=""/>
|
||||
</General>
|
||||
<VersionInfo>
|
||||
<StringTable Comments="" CompanyName="" FileDescription="" FileVersion="0.0.0.0" InternalName="" LegalCopyright="" LegalTrademarks="" OriginalFilename="" ProductName="" ProductVersion="0.0.0.0"/>
|
||||
</VersionInfo>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||
@ -33,9 +37,9 @@
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="waitforunit1.pas"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ResourceFilename Value="waitforunit1.lrs"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="WaitForUnit1"/>
|
||||
</Unit1>
|
||||
</Units>
|
||||
|
@ -11,6 +11,7 @@ object Form1: TForm1
|
||||
ClientWidth = 394
|
||||
OnCreate = FormCreate
|
||||
OnDestroy = FormDestroy
|
||||
LCLVersion = '0.9.29'
|
||||
object Button1: TButton
|
||||
Left = 32
|
||||
Height = 25
|
||||
@ -22,9 +23,11 @@ object Form1: TForm1
|
||||
TabOrder = 0
|
||||
end
|
||||
object Memo1: TMemo
|
||||
Left = 0
|
||||
Height = 303
|
||||
Top = 56
|
||||
Width = 394
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
ScrollBars = ssAutoBoth
|
||||
TabOrder = 1
|
||||
end
|
||||
|
@ -1,13 +1,14 @@
|
||||
{ Dies ist eine automatisch erzeugte Lazarus-Ressourcendatei }
|
||||
{ This is an automatically generated lazarus resource file }
|
||||
|
||||
LazarusResources.Add('TForm1','FORMDATA',[
|
||||
'TPF0'#6'TForm1'#5'Form1'#4'Left'#3#30#1#6'Height'#3'g'#1#3'Top'#3#202#0#5'Wi'
|
||||
+'dth'#3#138#1#18'HorzScrollBar.Page'#3#137#1#18'VertScrollBar.Page'#3'f'#1#13
|
||||
+'ActiveControl'#7#7'Button1'#7'Caption'#6#5'Form1'#12'ClientHeight'#3'g'#1#11
|
||||
+'ClientWidth'#3#138#1#8'OnCreate'#7#10'FormCreate'#9'OnDestroy'#7#11'FormDes'
|
||||
+'troy'#0#7'TButton'#7'Button1'#4'Left'#2' '#6'Height'#2#25#3'Top'#2#16#5'Wid'
|
||||
+'th'#2'K'#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#5'Start'#7'OnClick'
|
||||
+#7#12'Button1Click'#8'TabOrder'#2#0#0#0#5'TMemo'#5'Memo1'#6'Height'#3'/'#1#3
|
||||
+'Top'#2'8'#5'Width'#3#138#1#10'ScrollBars'#7#10'ssAutoBoth'#8'TabOrder'#2#1#0
|
||||
+#0#0
|
||||
+'troy'#10'LCLVersion'#6#6'0.9.29'#0#7'TButton'#7'Button1'#4'Left'#2' '#6'Hei'
|
||||
+'ght'#2#25#3'Top'#2#16#5'Width'#2'K'#25'BorderSpacing.InnerBorder'#2#4#7'Cap'
|
||||
+'tion'#6#5'Start'#7'OnClick'#7#12'Button1Click'#8'TabOrder'#2#0#0#0#5'TMemo'
|
||||
+#5'Memo1'#4'Left'#2#0#6'Height'#3'/'#1#3'Top'#2'8'#5'Width'#3#138#1#7'Anchor'
|
||||
+'s'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBottom'#0#10'ScrollBars'#7#10'ssAut'
|
||||
+'oBoth'#8'TabOrder'#2#1#0#0#0
|
||||
]);
|
||||
|
Loading…
Reference in New Issue
Block a user