Changeset 162 for MicroThreading/Demo
- Timestamp:
- Feb 7, 2011, 1:04:27 PM (14 years ago)
- Location:
- MicroThreading/Demo
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
MicroThreading/Demo/Demo.lpi
r161 r162 31 31 </local> 32 32 </RunParams> 33 <RequiredPackages Count=" 2">33 <RequiredPackages Count="3"> 34 34 <Item1> 35 <PackageName Value="Microthreading"/> 35 <PackageName Value="LCLBase"/> 36 <MinVersion Major="1" Release="1" Valid="True"/> 36 37 </Item1> 37 38 <Item2> 39 <PackageName Value="Microthreading"/> 40 </Item2> 41 <Item3> 38 42 <PackageName Value="LCL"/> 39 </Item 2>43 </Item3> 40 44 </RequiredPackages> 41 <Units Count="2 4">45 <Units Count="28"> 42 46 <Unit0> 43 47 <Filename Value="Demo.lpr"/> … … 55 59 <ResourceBaseClass Value="Form"/> 56 60 <UnitName Value="UMainForm"/> 57 <EditorIndex Value=" 1"/>58 <WindowIndex Value="0"/> 59 <TopLine Value="3 69"/>60 <CursorPos X=" 1" Y="379"/>61 <EditorIndex Value="6"/> 62 <WindowIndex Value="0"/> 63 <TopLine Value="372"/> 64 <CursorPos X="21" Y="378"/> 61 65 <UsageCount Value="270"/> 62 66 <Loaded Value="True"/> 67 <LoadedDesigner Value="True"/> 63 68 </Unit1> 64 69 <Unit2> … … 68 73 <EditorIndex Value="0"/> 69 74 <WindowIndex Value="0"/> 70 <TopLine Value=" 500"/>71 <CursorPos X="1 " Y="517"/>75 <TopLine Value="976"/> 76 <CursorPos X="18" Y="986"/> 72 77 <UsageCount Value="136"/> 73 78 <Loaded Value="True"/> … … 131 136 <ResourceBaseClass Value="Form"/> 132 137 <UnitName Value="UMicroThreadList"/> 133 <WindowIndex Value="0"/> 134 <TopLine Value="1"/> 135 <CursorPos X="44" Y="17"/> 136 <UsageCount Value="21"/> 138 <EditorIndex Value="4"/> 139 <WindowIndex Value="0"/> 140 <TopLine Value="83"/> 141 <CursorPos X="84" Y="94"/> 142 <UsageCount Value="23"/> 143 <Loaded Value="True"/> 144 <LoadedDesigner Value="True"/> 137 145 </Unit10> 138 146 <Unit11> … … 228 236 <UsageCount Value="16"/> 229 237 </Unit23> 238 <Unit24> 239 <Filename Value="../../../../Projekty2/FreePascalManager/trunk/Instance/1/FPC/packages/fcl-base/src/syncobjs.pp"/> 240 <UnitName Value="syncobjs"/> 241 <EditorIndex Value="5"/> 242 <WindowIndex Value="0"/> 243 <TopLine Value="35"/> 244 <CursorPos X="18" Y="45"/> 245 <UsageCount Value="12"/> 246 <Loaded Value="True"/> 247 </Unit24> 248 <Unit25> 249 <Filename Value="../../../../Projekty2/FreePascalManager/trunk/Instance/1/Lazarus/lcl/include/customlistview.inc"/> 250 <EditorIndex Value="1"/> 251 <WindowIndex Value="0"/> 252 <TopLine Value="548"/> 253 <CursorPos X="1" Y="561"/> 254 <UsageCount Value="11"/> 255 <Loaded Value="True"/> 256 </Unit25> 257 <Unit26> 258 <Filename Value="../../../../Projekty2/FreePascalManager/trunk/Instance/1/Lazarus/lcl/include/listitem.inc"/> 259 <EditorIndex Value="2"/> 260 <WindowIndex Value="0"/> 261 <TopLine Value="798"/> 262 <CursorPos X="1" Y="821"/> 263 <UsageCount Value="11"/> 264 <Loaded Value="True"/> 265 </Unit26> 266 <Unit27> 267 <Filename Value="../../../../Projekty2/FreePascalManager/trunk/Instance/1/Lazarus/lcl/include/listitems.inc"/> 268 <EditorIndex Value="3"/> 269 <WindowIndex Value="0"/> 270 <TopLine Value="65"/> 271 <CursorPos X="29" Y="75"/> 272 <UsageCount Value="11"/> 273 <Loaded Value="True"/> 274 </Unit27> 230 275 </Units> 231 276 <JumpHistory Count="30" HistoryIndex="29"> 232 277 <Position1> 233 278 <Filename Value="../UMicroThreading.pas"/> 234 <Caret Line=" 462" Column="1" TopLine="451"/>279 <Caret Line="371" Column="16" TopLine="350"/> 235 280 </Position1> 236 281 <Position2> 237 282 <Filename Value="../UMicroThreading.pas"/> 238 <Caret Line=" 463" Column="1" TopLine="451"/>283 <Caret Line="652" Column="38" TopLine="631"/> 239 284 </Position2> 240 285 <Position3> 241 286 <Filename Value="../UMicroThreading.pas"/> 242 <Caret Line=" 434" Column="1" TopLine="423"/>287 <Caret Line="746" Column="12" TopLine="725"/> 243 288 </Position3> 244 289 <Position4> 245 290 <Filename Value="../UMicroThreading.pas"/> 246 <Caret Line=" 462" Column="1" TopLine="451"/>291 <Caret Line="750" Column="31" TopLine="729"/> 247 292 </Position4> 248 293 <Position5> 249 294 <Filename Value="../UMicroThreading.pas"/> 250 <Caret Line=" 463" Column="1" TopLine="451"/>295 <Caret Line="753" Column="26" TopLine="732"/> 251 296 </Position5> 252 297 <Position6> 253 298 <Filename Value="../UMicroThreading.pas"/> 254 <Caret Line=" 545" Column="1" TopLine="534"/>299 <Caret Line="935" Column="13" TopLine="914"/> 255 300 </Position6> 256 301 <Position7> 257 302 <Filename Value="../UMicroThreading.pas"/> 258 <Caret Line=" 429" Column="1" TopLine="418"/>303 <Caret Line="983" Column="31" TopLine="968"/> 259 304 </Position7> 260 305 <Position8> 261 306 <Filename Value="../UMicroThreading.pas"/> 262 <Caret Line=" 430" Column="1" TopLine="418"/>307 <Caret Line="1013" Column="24" TopLine="992"/> 263 308 </Position8> 264 309 <Position9> 265 310 <Filename Value="../UMicroThreading.pas"/> 266 <Caret Line=" 574" Column="1" TopLine="563"/>311 <Caret Line="8" Column="19" TopLine="1"/> 267 312 </Position9> 268 313 <Position10> 269 314 <Filename Value="../UMicroThreading.pas"/> 270 <Caret Line=" 575" Column="1" TopLine="563"/>315 <Caret Line="652" Column="51" TopLine="639"/> 271 316 </Position10> 272 317 <Position11> 273 318 <Filename Value="../UMicroThreading.pas"/> 274 <Caret Line=" 576" Column="1" TopLine="563"/>319 <Caret Line="645" Column="28" TopLine="639"/> 275 320 </Position11> 276 321 <Position12> 277 322 <Filename Value="../UMicroThreading.pas"/> 278 <Caret Line=" 572" Column="1" TopLine="563"/>323 <Caret Line="653" Column="43" TopLine="639"/> 279 324 </Position12> 280 325 <Position13> 281 326 <Filename Value="../UMicroThreading.pas"/> 282 <Caret Line=" 573" Column="1" TopLine="563"/>327 <Caret Line="479" Column="1" TopLine="466"/> 283 328 </Position13> 284 329 <Position14> 285 330 <Filename Value="../UMicroThreading.pas"/> 286 <Caret Line=" 434" Column="1" TopLine="423"/>331 <Caret Line="712" Column="1" TopLine="699"/> 287 332 </Position14> 288 333 <Position15> 289 334 <Filename Value="../UMicroThreading.pas"/> 290 <Caret Line=" 462" Column="1" TopLine="451"/>335 <Caret Line="582" Column="18" TopLine="571"/> 291 336 </Position15> 292 337 <Position16> 293 338 <Filename Value="../UMicroThreading.pas"/> 294 <Caret Line=" 463" Column="1" TopLine="451"/>339 <Caret Line="583" Column="65" TopLine="571"/> 295 340 </Position16> 296 341 <Position17> 297 342 <Filename Value="../UMicroThreading.pas"/> 298 <Caret Line="5 45" Column="30" TopLine="534"/>343 <Caret Line="582" Column="20" TopLine="571"/> 299 344 </Position17> 300 345 <Position18> 301 346 <Filename Value="../UMicroThreading.pas"/> 302 <Caret Line=" 429" Column="1" TopLine="418"/>347 <Caret Line="583" Column="1" TopLine="571"/> 303 348 </Position18> 304 349 <Position19> 305 350 <Filename Value="../UMicroThreading.pas"/> 306 <Caret Line=" 430" Column="1" TopLine="418"/>351 <Caret Line="711" Column="1" TopLine="698"/> 307 352 </Position19> 308 353 <Position20> 309 354 <Filename Value="../UMicroThreading.pas"/> 310 <Caret Line=" 574" Column="1" TopLine="563"/>355 <Caret Line="712" Column="1" TopLine="698"/> 311 356 </Position20> 312 357 <Position21> 313 358 <Filename Value="../UMicroThreading.pas"/> 314 <Caret Line=" 575" Column="1" TopLine="563"/>359 <Caret Line="713" Column="1" TopLine="698"/> 315 360 </Position21> 316 361 <Position22> 317 362 <Filename Value="../UMicroThreading.pas"/> 318 <Caret Line=" 513" Column="34" TopLine="504"/>363 <Caret Line="714" Column="1" TopLine="698"/> 319 364 </Position22> 320 365 <Position23> 321 366 <Filename Value="../UMicroThreading.pas"/> 322 <Caret Line=" 517" Column="1" TopLine="504"/>367 <Caret Line="715" Column="1" TopLine="698"/> 323 368 </Position23> 324 369 <Position24> 325 <Filename Value="../UMicroThread ing.pas"/>326 <Caret Line=" 545" Column="1" TopLine="534"/>370 <Filename Value="../UMicroThreadList.pas"/> 371 <Caret Line="95" Column="54" TopLine="83"/> 327 372 </Position24> 328 373 <Position25> 329 <Filename Value=" UMainForm.pas"/>330 <Caret Line=" 379" Column="1" TopLine="369"/>374 <Filename Value="../UMicroThreading.pas"/> 375 <Caret Line="240" Column="45" TopLine="227"/> 331 376 </Position25> 332 377 <Position26> 333 378 <Filename Value="../UMicroThreading.pas"/> 334 <Caret Line=" 613" Column="1" TopLine="602"/>379 <Caret Line="984" Column="40" TopLine="979"/> 335 380 </Position26> 336 381 <Position27> 337 382 <Filename Value="../UMicroThreading.pas"/> 338 <Caret Line=" 428" Column="6" TopLine="417"/>383 <Caret Line="992" Column="38" TopLine="979"/> 339 384 </Position27> 340 385 <Position28> 341 386 <Filename Value="../UMicroThreading.pas"/> 342 <Caret Line=" 434" Column="3" TopLine="504"/>387 <Caret Line="989" Column="55" TopLine="976"/> 343 388 </Position28> 344 389 <Position29> 345 390 <Filename Value="../UMicroThreading.pas"/> 346 <Caret Line=" 579" Column="1" TopLine="568"/>391 <Caret Line="990" Column="24" TopLine="976"/> 347 392 </Position29> 348 393 <Position30> 349 394 <Filename Value="../UMicroThreading.pas"/> 350 <Caret Line=" 435" Column="1" TopLine="424"/>395 <Caret Line="989" Column="29" TopLine="976"/> 351 396 </Position30> 352 397 </JumpHistory> … … 389 434 </CompilerOptions> 390 435 <Debugging> 391 <BreakPoints Count=" 2">436 <BreakPoints Count="3"> 392 437 <Item1> 393 438 <Source Value="../UMicroThreading.pas"/> 394 <Line Value="2 61"/>439 <Line Value="280"/> 395 440 </Item1> 396 441 <Item2> … … 398 443 <Line Value="1036"/> 399 444 </Item2> 445 <Item3> 446 <Source Value="../UMicroThreading.pas"/> 447 <Line Value="321"/> 448 </Item3> 400 449 </BreakPoints> 401 450 <Watches Count="2"> -
MicroThreading/Demo/UMainForm.lfm
r160 r162 16 16 Top = 8 17 17 Width = 802 18 ActivePage = TabSheet 118 ActivePage = TabSheet2 19 19 Anchors = [akTop, akLeft, akRight, akBottom] 20 TabIndex = 120 TabIndex = 0 21 21 TabOrder = 0 22 22 object TabSheet2: TTabSheet … … 26 26 object GroupBox1: TGroupBox 27 27 Left = 6 28 Height = 8128 Height = 123 29 29 Top = 143 30 30 Width = 205 31 31 Caption = 'State' 32 ClientHeight = 6332 ClientHeight = 105 33 33 ClientWidth = 201 34 34 TabOrder = 0 … … 142 142 end 143 143 end 144 object ListView2: TListView145 Left = 6146 Height = 237147 Top = 247148 Width = 206149 Anchors = [akTop, akLeft, akBottom]150 Columns = <151 item152 Caption = 'Id'153 end154 item155 Caption = 'State'156 Width = 135157 end>158 OwnerData = True159 TabOrder = 2160 ViewStyle = vsReport161 OnData = ListView2Data162 end163 object Label13: TLabel164 Left = 7165 Height = 14166 Top = 233167 Width = 44168 Caption = 'Threads:'169 ParentColor = False170 end171 144 object Button4: TButton 172 145 Left = 226 … … 176 149 Caption = 'Show manager' 177 150 OnClick = Button4Click 178 TabOrder = 3151 TabOrder = 2 179 152 end 180 153 end … … 195 168 Left = 10 196 169 Height = 25 197 Top = 2 23170 Top = 266 198 171 Width = 104 199 172 Caption = 'Clear jobs' … … 230 203 end 231 204 object Button1: TButton 232 Left = 230233 Height = 25 234 Top = 2 39205 Left = 316 206 Height = 25 207 Top = 266 235 208 Width = 75 236 209 Caption = 'Clear memo' … … 258 231 object GroupBox3: TGroupBox 259 232 Left = 10 260 Height = 1 37233 Height = 185 261 234 Top = 74 262 235 Width = 292 263 236 Caption = 'Do inside jobs' 264 ClientHeight = 1 19237 ClientHeight = 167 265 238 ClientWidth = 288 266 239 TabOrder = 6 … … 280 253 Width = 90 281 254 MaxValue = 100000 255 OnChange = CheckBox1Change 282 256 TabOrder = 1 283 257 Value = 100 … … 345 319 TabOrder = 6 346 320 end 321 object CheckBox4: TCheckBox 322 Left = 6 323 Height = 17 324 Top = 110 325 Width = 123 326 Caption = 'Wait in critical section' 327 OnChange = CheckBox4Change 328 TabOrder = 7 329 end 330 object SpinEdit6: TSpinEdit 331 Left = 186 332 Height = 21 333 Top = 104 334 Width = 70 335 MaxValue = 100000 336 OnChange = CheckBox4Change 337 TabOrder = 8 338 Value = 100 339 end 340 object Label18: TLabel 341 Left = 264 342 Height = 14 343 Top = 110 344 Width = 14 345 Caption = 'ms' 346 ParentColor = False 347 end 347 348 end 348 349 end -
MicroThreading/Demo/UMainForm.pas
r161 r162 20 20 MainForm: TMainForm; 21 21 procedure DoWriteToMemo; 22 constructor Create(CreateSuspended: Boolean; 23 const StackSize: SizeUInt = DefaultStackSize); 24 destructor Destroy; override; 22 25 end; 23 26 … … 38 41 CheckBox2: TCheckBox; 39 42 CheckBox3: TCheckBox; 43 CheckBox4: TCheckBox; 40 44 CheckBoxUseMainThread: TCheckBox; 41 45 GroupBox1: TGroupBox; … … 45 49 Label11: TLabel; 46 50 Label12: TLabel; 47 Label13: TLabel;48 51 Label14: TLabel; 49 52 Label15: TLabel; 50 53 Label16: TLabel; 51 54 Label17: TLabel; 55 Label18: TLabel; 52 56 Label2: TLabel; 53 57 Label3: TLabel; … … 58 62 Label8: TLabel; 59 63 Label9: TLabel; 60 ListView2: TListView;61 64 Memo1: TMemo; 62 65 PageControl1: TPageControl; … … 66 69 SpinEdit4: TSpinEdit; 67 70 SpinEdit5: TSpinEdit; 71 SpinEdit6: TSpinEdit; 68 72 TabSheet1: TTabSheet; 69 73 TabSheet2: TTabSheet; … … 83 87 procedure CheckBox2Change(Sender: TObject); 84 88 procedure CheckBox3Change(Sender: TObject); 89 procedure CheckBox4Change(Sender: TObject); 85 90 procedure CheckBoxUseMainThreadChange(Sender: TObject); 86 91 procedure FormCreate(Sender: TObject); … … 91 96 procedure SpinEdit3Change(Sender: TObject); 92 97 procedure SpinEdit5Change(Sender: TObject); 98 procedure SpinEdit6Change(Sender: TObject); 93 99 procedure TimerRedrawTimer(Sender: TObject); 94 100 private 95 101 MicroThreadList: TMicroThreadList; 102 Lock: TMicroThreadCriticalSection; 96 103 LastException: Exception; 97 104 LastExceptionSender: TObject; … … 102 109 DoWriteToMemo: Boolean; 103 110 DoSleep: Boolean; 111 DoCriticalSection: Boolean; 104 112 RaiseException: Boolean; 105 113 SleepDuration: Integer; 114 CriticalSectionSleepDuration: Integer; 106 115 DoWaitForEvent: Boolean; 107 116 Event: TMicroThreadEvent; … … 129 138 MicroThreadList := TMicroThreadList.Create(Self); 130 139 UMicroThreading.ExceptionHandler := ShowException; 140 Lock := TMicroThreadCriticalSection.Create; 131 141 end; 132 142 … … 280 290 end; 281 291 292 procedure TMainForm.CheckBox4Change(Sender: TObject); 293 begin 294 CriticalSectionSleepDuration := SpinEdit4.Value; 295 DoCriticalSection := CheckBox4.Checked; 296 end; 297 282 298 procedure TMainForm.CheckBoxUseMainThreadChange(Sender: TObject); 283 299 begin … … 290 306 MainScheduler.Active := False; 291 307 Event.Free; 308 Lock.Free; 292 309 end; 293 310 … … 303 320 procedure TMainForm.ListView2Data(Sender: TObject; Item: TListItem); 304 321 begin 305 if Item.Index < MainScheduler.ThreadPoolCount then306 try307 MainScheduler.ThreadPoolLock.Acquire;308 with TMicroThreadThread(MainScheduler.ThreadPool[Item.Index]) do begin309 Item.Caption := IntToStr(ThreadID);310 Item.SubItems.Add(MicroThreadThreadStateText[State]);311 end;312 finally313 MainScheduler.ThreadPoolLock.Release;314 end;315 322 end; 316 323 … … 330 337 end; 331 338 339 procedure TMainForm.SpinEdit6Change(Sender: TObject); 340 begin 341 end; 342 332 343 procedure TMainForm.TimerRedrawTimer(Sender: TObject); 333 344 begin 334 if ListView2.Items.Count <> MainScheduler.ThreadPoolCount then335 ListView2.Items.Count := MainScheduler.ThreadPoolCount;336 ListView2.Items[-1];337 ListView2.Refresh;338 339 345 Label2.Caption := DateTimeToStr(NowPrecise) + ' ' + 340 346 FloatToStr(Frac(NowPrecise / OneSecond)); … … 369 375 begin 370 376 for I := 0 to MainForm.Iterations - 1 do begin 371 try372 377 Q := 0; 373 while Q < 100 do Inc(Q);378 while Q < 100000 do Inc(Q); 374 379 if MainForm.DoWriteToMemo then Synchronize(DoWriteToMemo); 375 380 if MainForm.DoWaitForEvent then MainForm.Event.WaitFor(MainForm.WaitForEventDuration * OneMillisecond); … … 379 384 raise Exception.Create('Exception from microthread'); 380 385 end; 386 if MainForm.DoCriticalSection then begin 387 try 388 MainForm.Lock.Acquire; 389 MTSleep(MainForm.CriticalSectionSleepDuration * OneMillisecond); 390 finally 391 MainForm.Lock.Release; 392 end; 393 end; 381 394 //WorkerSubRoutine; 382 395 Completion := I / MainForm.Iterations; 383 396 Yield; 384 385 except386 Q := 0;387 raise Exception.Create('Exception from microthread');388 end;389 397 end; 390 398 end; … … 395 403 end; 396 404 405 constructor TWorker.Create(CreateSuspended: Boolean; const StackSize: SizeUInt); 406 begin 407 inherited; 408 end; 409 410 destructor TWorker.Destroy; 411 begin 412 inherited Destroy; 413 end; 414 397 415 end. 398 416
Note:
See TracChangeset
for help on using the changeset viewer.