From 6ec276af67d4f86cbdadb20b8808aa63e2e3e862 Mon Sep 17 00:00:00 2001 From: maxim Date: Tue, 16 Mar 2010 21:52:31 +0000 Subject: [PATCH] examples: fixed multithreading examples compilation with trunk FPC (2.5.1). Patch from alexs. git-svn-id: trunk@24054 - --- .../criticalsectionexample1.lpi | 14 ++++--- .../multithreading/criticalsectionunit1.lfm | 38 +++++++++---------- .../multithreading/criticalsectionunit1.lrs | 27 ++++++------- .../multithreading/criticalsectionunit1.pas | 9 +++-- .../multithreading/multithreadingexample1.lpi | 14 ++++--- .../multithreading/processmessagesunit1.lfm | 32 ++++++++-------- .../multithreading/processmessagesunit1.lrs | 22 +++++------ .../multithreading/processmessagesunit1.pas | 8 ++-- .../singlethreadingexample1.lpi | 14 ++++--- examples/multithreading/waitforexample1.lpi | 14 ++++--- examples/multithreading/waitforunit1.lfm | 3 ++ examples/multithreading/waitforunit1.lrs | 13 ++++--- 12 files changed, 118 insertions(+), 90 deletions(-) diff --git a/examples/multithreading/criticalsectionexample1.lpi b/examples/multithreading/criticalsectionexample1.lpi index caa68e094e..ff9e3979b8 100644 --- a/examples/multithreading/criticalsectionexample1.lpi +++ b/examples/multithreading/criticalsectionexample1.lpi @@ -1,14 +1,18 @@ - - + + + + - + + + @@ -34,9 +38,9 @@ - - + + diff --git a/examples/multithreading/criticalsectionunit1.lfm b/examples/multithreading/criticalsectionunit1.lfm index 5647a70364..80e9c78165 100644 --- a/examples/multithreading/criticalsectionunit1.lfm +++ b/examples/multithreading/criticalsectionunit1.lfm @@ -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 diff --git a/examples/multithreading/criticalsectionunit1.lrs b/examples/multithreading/criticalsectionunit1.lrs index 02a5499c47..5cae37a3fd 100644 --- a/examples/multithreading/criticalsectionunit1.lrs +++ b/examples/multithreading/criticalsectionunit1.lrs @@ -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 ]); diff --git a/examples/multithreading/criticalsectionunit1.pas b/examples/multithreading/criticalsectionunit1.pas index 1819a98018..fdac3758cb 100644 --- a/examples/multithreading/criticalsectionunit1.pas +++ b/examples/multithreading/criticalsectionunit1.pas @@ -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 diff --git a/examples/multithreading/multithreadingexample1.lpi b/examples/multithreading/multithreadingexample1.lpi index a4d76f15c3..ed4b39dde8 100644 --- a/examples/multithreading/multithreadingexample1.lpi +++ b/examples/multithreading/multithreadingexample1.lpi @@ -1,14 +1,18 @@ - - + + + + - + + + @@ -33,9 +37,9 @@ - - + + diff --git a/examples/multithreading/processmessagesunit1.lfm b/examples/multithreading/processmessagesunit1.lfm index cf7e0b834c..5cd832637b 100644 --- a/examples/multithreading/processmessagesunit1.lfm +++ b/examples/multithreading/processmessagesunit1.lfm @@ -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 diff --git a/examples/multithreading/processmessagesunit1.lrs b/examples/multithreading/processmessagesunit1.lrs index 9b6a9e3db7..0a65b387c6 100644 --- a/examples/multithreading/processmessagesunit1.lrs +++ b/examples/multithreading/processmessagesunit1.lrs @@ -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 ]); diff --git a/examples/multithreading/processmessagesunit1.pas b/examples/multithreading/processmessagesunit1.pas index 68bd4f4dd1..d8dbaae4a0 100644 --- a/examples/multithreading/processmessagesunit1.pas +++ b/examples/multithreading/processmessagesunit1.pas @@ -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; diff --git a/examples/multithreading/singlethreadingexample1.lpi b/examples/multithreading/singlethreadingexample1.lpi index dbaccf5998..fd5cc83d70 100644 --- a/examples/multithreading/singlethreadingexample1.lpi +++ b/examples/multithreading/singlethreadingexample1.lpi @@ -1,14 +1,18 @@ - - + + + + - + + + @@ -34,9 +38,9 @@ - - + + diff --git a/examples/multithreading/waitforexample1.lpi b/examples/multithreading/waitforexample1.lpi index f1711018fd..23c6d49f9f 100644 --- a/examples/multithreading/waitforexample1.lpi +++ b/examples/multithreading/waitforexample1.lpi @@ -1,14 +1,18 @@ - - + + + + - + + + @@ -33,9 +37,9 @@ - - + + diff --git a/examples/multithreading/waitforunit1.lfm b/examples/multithreading/waitforunit1.lfm index 0d9774d267..6a406f0eb2 100644 --- a/examples/multithreading/waitforunit1.lfm +++ b/examples/multithreading/waitforunit1.lfm @@ -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 diff --git a/examples/multithreading/waitforunit1.lrs b/examples/multithreading/waitforunit1.lrs index 0b6532fea7..a849d7bdab 100644 --- a/examples/multithreading/waitforunit1.lrs +++ b/examples/multithreading/waitforunit1.lrs @@ -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 ]);