Changeset 154 for MicroThreading/Demo
- Timestamp:
- Jan 27, 2011, 2:15:57 PM (14 years ago)
- Location:
- MicroThreading/Demo
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
MicroThreading/Demo/Demo.lpi
r153 r154 39 39 </Item2> 40 40 </RequiredPackages> 41 <Units Count="6 2">41 <Units Count="63"> 42 42 <Unit0> 43 43 <Filename Value="Demo.lpr"/> 44 44 <IsPartOfProject Value="True"/> 45 45 <UnitName Value="Demo"/> 46 <EditorIndex Value="4"/> 46 47 <WindowIndex Value="0"/> 47 48 <TopLine Value="1"/> 48 <CursorPos X="5" Y="9"/> 49 <UsageCount Value="68"/> 49 <CursorPos X="21" Y="18"/> 50 <UsageCount Value="69"/> 51 <Loaded Value="True"/> 50 52 </Unit0> 51 53 <Unit1> … … 57 59 <EditorIndex Value="0"/> 58 60 <WindowIndex Value="0"/> 59 <TopLine Value=" 1"/>60 <CursorPos X=" 15" Y="67"/>61 <UsageCount Value="6 8"/>61 <TopLine Value="263"/> 62 <CursorPos X="8" Y="276"/> 63 <UsageCount Value="69"/> 62 64 <Loaded Value="True"/> 63 65 <LoadedDesigner Value="True"/> … … 67 69 <UnitName Value="UMicroThreading"/> 68 70 <IsVisibleTab Value="True"/> 69 <EditorIndex Value=" 1"/>70 <WindowIndex Value="0"/> 71 <TopLine Value=" 446"/>72 <CursorPos X=" 6" Y="450"/>71 <EditorIndex Value="2"/> 72 <WindowIndex Value="0"/> 73 <TopLine Value="51"/> 74 <CursorPos X="22" Y="54"/> 73 75 <UsageCount Value="37"/> 74 76 <Loaded Value="True"/> … … 293 295 <Unit32> 294 296 <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/objpas/classes/classesh.inc"/> 295 <EditorIndex Value=" 5"/>297 <EditorIndex Value="8"/> 296 298 <WindowIndex Value="0"/> 297 299 <TopLine Value="1467"/> … … 302 304 <Unit33> 303 305 <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/win/tthread.inc"/> 304 <EditorIndex Value=" 6"/>306 <EditorIndex Value="9"/> 305 307 <WindowIndex Value="0"/> 306 308 <TopLine Value="52"/> … … 325 327 <Unit36> 326 328 <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/objpas/classes/classes.inc"/> 327 <EditorIndex Value=" 7"/>329 <EditorIndex Value="10"/> 328 330 <WindowIndex Value="0"/> 329 331 <TopLine Value="124"/> … … 341 343 <Unit38> 342 344 <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/objpas/sysutils/osutilsh.inc"/> 343 <EditorIndex Value=" 2"/>345 <EditorIndex Value="5"/> 344 346 <WindowIndex Value="0"/> 345 347 <TopLine Value="14"/> 346 <CursorPos X="1 1" Y="27"/>348 <CursorPos X="17" Y="27"/> 347 349 <UsageCount Value="13"/> 348 350 <Loaded Value="True"/> … … 357 359 <Unit40> 358 360 <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/inc/systemh.inc"/> 359 <WindowIndex Value="0"/> 360 <TopLine Value="492"/> 361 <CursorPos X="3" Y="504"/> 362 <UsageCount Value="9"/> 361 <EditorIndex Value="3"/> 362 <WindowIndex Value="0"/> 363 <TopLine Value="480"/> 364 <CursorPos X="3" Y="493"/> 365 <UsageCount Value="10"/> 366 <Loaded Value="True"/> 363 367 </Unit40> 364 368 <Unit41> … … 414 418 <Filename Value="../UPlatform.pas"/> 415 419 <UnitName Value="UPlatform"/> 416 <EditorIndex Value=" 9"/>417 <WindowIndex Value="0"/> 418 <TopLine Value="1 "/>419 <CursorPos X="1 4" Y="1"/>420 <EditorIndex Value="12"/> 421 <WindowIndex Value="0"/> 422 <TopLine Value="19"/> 423 <CursorPos X="1" Y="41"/> 420 424 <UsageCount Value="17"/> 421 425 <Loaded Value="True"/> … … 481 485 <Unit57> 482 486 <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/objpas/classes/lists.inc"/> 483 <EditorIndex Value=" 8"/>487 <EditorIndex Value="11"/> 484 488 <WindowIndex Value="0"/> 485 489 <TopLine Value="590"/> … … 490 494 <Unit58> 491 495 <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/lcl/interfaces/win32/win32callback.inc"/> 492 <EditorIndex Value=" 4"/>496 <EditorIndex Value="7"/> 493 497 <WindowIndex Value="0"/> 494 498 <TopLine Value="1086"/> … … 508 512 <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/lcl/customtimer.pas"/> 509 513 <UnitName Value="CustomTimer"/> 510 <EditorIndex Value=" 3"/>514 <EditorIndex Value="6"/> 511 515 <WindowIndex Value="0"/> 512 516 <TopLine Value="40"/> … … 517 521 <Unit61> 518 522 <Filename Value="../ReadMe.txt"/> 519 <EditorIndex Value="1 0"/>523 <EditorIndex Value="13"/> 520 524 <WindowIndex Value="0"/> 521 525 <TopLine Value="1"/> … … 525 529 <DefaultSyntaxHighlighter Value="None"/> 526 530 </Unit61> 531 <Unit62> 532 <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/lcl/forms.pp"/> 533 <UnitName Value="Forms"/> 534 <EditorIndex Value="1"/> 535 <WindowIndex Value="0"/> 536 <TopLine Value="57"/> 537 <CursorPos X="3" Y="70"/> 538 <UsageCount Value="10"/> 539 <Loaded Value="True"/> 540 </Unit62> 527 541 </Units> 528 542 <JumpHistory Count="30" HistoryIndex="29"> 529 543 <Position1> 530 544 <Filename Value="../UMicroThreading.pas"/> 531 <Caret Line="2 79" Column="19" TopLine="267"/>545 <Caret Line="250" Column="1" TopLine="228"/> 532 546 </Position1> 533 547 <Position2> 534 548 <Filename Value="../UMicroThreading.pas"/> 535 <Caret Line=" 295" Column="1" TopLine="270"/>549 <Caret Line="472" Column="1" TopLine="459"/> 536 550 </Position2> 537 551 <Position3> 538 552 <Filename Value="../UMicroThreading.pas"/> 539 <Caret Line=" 289" Column="1" TopLine="270"/>553 <Caret Line="473" Column="1" TopLine="459"/> 540 554 </Position3> 541 555 <Position4> 542 556 <Filename Value="../UMicroThreading.pas"/> 543 <Caret Line=" 290" Column="1" TopLine="270"/>557 <Caret Line="474" Column="1" TopLine="459"/> 544 558 </Position4> 545 559 <Position5> 546 560 <Filename Value="../UMicroThreading.pas"/> 547 <Caret Line=" 291" Column="1" TopLine="270"/>561 <Caret Line="459" Column="1" TopLine="446"/> 548 562 </Position5> 549 563 <Position6> 550 564 <Filename Value="../UMicroThreading.pas"/> 551 <Caret Line="2 92" Column="1" TopLine="270"/>565 <Caret Line="267" Column="1" TopLine="254"/> 552 566 </Position6> 553 567 <Position7> 554 568 <Filename Value="../UMicroThreading.pas"/> 555 <Caret Line=" 598" Column="50" TopLine="587"/>569 <Caret Line="268" Column="1" TopLine="254"/> 556 570 </Position7> 557 571 <Position8> 558 <Filename Value="../U MicroThreading.pas"/>559 <Caret Line="29 1" Column="40" TopLine="278"/>572 <Filename Value="../UPlatform.pas"/> 573 <Caret Line="29" Column="1" TopLine="16"/> 560 574 </Position8> 561 575 <Position9> 562 <Filename Value="../U MicroThreading.pas"/>563 <Caret Line=" 280" Column="1" TopLine="272"/>576 <Filename Value="../UPlatform.pas"/> 577 <Caret Line="31" Column="1" TopLine="16"/> 564 578 </Position9> 565 579 <Position10> 566 <Filename Value="../U MicroThreading.pas"/>567 <Caret Line=" 288" Column="26" TopLine="272"/>580 <Filename Value="../UPlatform.pas"/> 581 <Caret Line="40" Column="1" TopLine="18"/> 568 582 </Position10> 569 583 <Position11> 570 <Filename Value="../U MicroThreading.pas"/>571 <Caret Line=" 285" Column="35" TopLine="272"/>584 <Filename Value="../UPlatform.pas"/> 585 <Caret Line="41" Column="1" TopLine="19"/> 572 586 </Position11> 573 587 <Position12> 574 588 <Filename Value="../UMicroThreading.pas"/> 575 <Caret Line="2 88" Column="1" TopLine="272"/>589 <Caret Line="269" Column="1" TopLine="254"/> 576 590 </Position12> 577 591 <Position13> 578 592 <Filename Value="../UMicroThreading.pas"/> 579 <Caret Line="2 89" Column="1" TopLine="272"/>593 <Caret Line="270" Column="1" TopLine="260"/> 580 594 </Position13> 581 595 <Position14> 582 596 <Filename Value="../UMicroThreading.pas"/> 583 <Caret Line="2 90" Column="1" TopLine="272"/>597 <Caret Line="273" Column="1" TopLine="260"/> 584 598 </Position14> 585 599 <Position15> 586 600 <Filename Value="../UMicroThreading.pas"/> 587 <Caret Line="2 91" Column="1" TopLine="272"/>601 <Caret Line="274" Column="1" TopLine="260"/> 588 602 </Position15> 589 603 <Position16> 590 604 <Filename Value="../UMicroThreading.pas"/> 591 <Caret Line="2 92" Column="1" TopLine="272"/>605 <Caret Line="275" Column="1" TopLine="260"/> 592 606 </Position16> 593 607 <Position17> 594 608 <Filename Value="../UMicroThreading.pas"/> 595 <Caret Line="2 93" Column="1" TopLine="272"/>609 <Caret Line="276" Column="1" TopLine="260"/> 596 610 </Position17> 597 611 <Position18> 598 612 <Filename Value="../UMicroThreading.pas"/> 599 <Caret Line="2 96" Column="1" TopLine="274"/>613 <Caret Line="277" Column="1" TopLine="260"/> 600 614 </Position18> 601 615 <Position19> 602 616 <Filename Value="../UMicroThreading.pas"/> 603 <Caret Line="2 97" Column="1" TopLine="275"/>617 <Caret Line="278" Column="1" TopLine="260"/> 604 618 </Position19> 605 619 <Position20> 606 620 <Filename Value="../UMicroThreading.pas"/> 607 <Caret Line="2 98" Column="1" TopLine="276"/>621 <Caret Line="281" Column="1" TopLine="260"/> 608 622 </Position20> 609 623 <Position21> 610 624 <Filename Value="../UMicroThreading.pas"/> 611 <Caret Line="2 99" Column="1" TopLine="277"/>625 <Caret Line="282" Column="1" TopLine="260"/> 612 626 </Position21> 613 627 <Position22> 614 628 <Filename Value="../UMicroThreading.pas"/> 615 <Caret Line=" 471" Column="1" TopLine="458"/>629 <Caret Line="283" Column="1" TopLine="261"/> 616 630 </Position22> 617 631 <Position23> 618 632 <Filename Value="../UMicroThreading.pas"/> 619 <Caret Line="28 5" Column="32" TopLine="275"/>633 <Caret Line="284" Column="1" TopLine="262"/> 620 634 </Position23> 621 635 <Position24> 622 <Filename Value="../ ../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/objpas/classes/classesh.inc"/>623 <Caret Line=" 1488" Column="37" TopLine="1467"/>636 <Filename Value="../UMicroThreading.pas"/> 637 <Caret Line="286" Column="1" TopLine="264"/> 624 638 </Position24> 625 639 <Position25> 626 <Filename Value=" ../UMicroThreading.pas"/>627 <Caret Line=" 71" Column="5" TopLine="55"/>640 <Filename Value="UMainForm.pas"/> 641 <Caret Line="276" Column="1" TopLine="263"/> 628 642 </Position25> 629 643 <Position26> 630 644 <Filename Value="../UMicroThreading.pas"/> 631 <Caret Line=" 125" Column="1" TopLine="110"/>645 <Caret Line="249" Column="1" TopLine="236"/> 632 646 </Position26> 633 647 <Position27> 634 <Filename Value=" UMainForm.pas"/>635 <Caret Line=" 68" Column="29" TopLine="54"/>648 <Filename Value="../UMicroThreading.pas"/> 649 <Caret Line="250" Column="1" TopLine="236"/> 636 650 </Position27> 637 651 <Position28> 638 <Filename Value=" ../UMicroThreading.pas"/>639 <Caret Line=" 566" Column="20" TopLine="561"/>652 <Filename Value="UMainForm.pas"/> 653 <Caret Line="276" Column="8" TopLine="263"/> 640 654 </Position28> 641 655 <Position29> 642 656 <Filename Value="../UMicroThreading.pas"/> 643 <Caret Line=" 567" Column="23" TopLine="554"/>657 <Caret Line="250" Column="29" TopLine="245"/> 644 658 </Position29> 645 659 <Position30> 646 660 <Filename Value="../UMicroThreading.pas"/> 647 <Caret Line=" 579" Column="51" TopLine="560"/>661 <Caret Line="64" Column="17" TopLine="51"/> 648 662 </Position30> 649 663 </JumpHistory> -
MicroThreading/Demo/UMainForm.pas
r153 r154 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 ComCtrls, ExtCtrls, Spin, UMicroThreading, Coroutine,DateUtils, UPlatform;9 ComCtrls, ExtCtrls, Spin, UMicroThreading, DateUtils, UPlatform; 10 10 11 11 type … … 67 67 procedure Worker(MicroThread: TMicroThread); 68 68 procedure WorkerDoWrite; 69 procedure WorkerSubRoutine; 69 70 public 70 71 Iterations: Integer; 71 Scheduler: TMicroThreadScheduler;72 72 end; 73 73 … … 85 85 procedure TMainForm.FormCreate(Sender: TObject); 86 86 begin 87 Scheduler := TMicroThreadScheduler.Create;88 87 DoubleBuffered := True; 89 88 ListView1.DoubleBuffered := True; … … 97 96 if ButtonSchedulerStartStop.Caption = 'Start scheduler' then begin 98 97 ButtonSchedulerStartStop.Caption := 'Stop scheduler'; 99 Scheduler.ThreadPoolSize := SpinEdit2.Value;100 Scheduler.Active := True;98 MainScheduler.ThreadPoolSize := SpinEdit2.Value; 99 MainScheduler.Active := True; 101 100 end else begin 102 101 ButtonSchedulerStartStop.Caption := 'Start scheduler'; 103 Scheduler.Active := False;102 MainScheduler.Active := False; 104 103 end; 105 104 end; … … 169 168 //Scheduler.FMicroThreads.Clear; 170 169 for I := 0 to SpinEdit1.Value - 1 do 171 Scheduler.AddMethod(Worker);170 MainScheduler.AddMethod(Worker); 172 171 end; 173 172 … … 197 196 begin 198 197 try 199 Scheduler.MicroThreadsLock.Acquire;200 Scheduler.MicroThreads.Clear;198 MainScheduler.MicroThreadsLock.Acquire; 199 MainScheduler.MicroThreads.Clear; 201 200 finally 202 Scheduler.MicroThreadsLock.Release;201 MainScheduler.MicroThreadsLock.Release; 203 202 end; 204 203 end; … … 206 205 procedure TMainForm.CheckBoxUseMainThreadChange(Sender: TObject); 207 206 begin 208 Scheduler.UseMainThread := CheckBoxUseMainThread.Checked;207 MainScheduler.UseMainThread := CheckBoxUseMainThread.Checked; 209 208 end; 210 209 211 210 procedure TMainForm.FormClose(Sender: TObject; var CloseAction: TCloseAction); 212 211 begin 213 Scheduler.Active := False;212 MainScheduler.Active := False; 214 213 end; 215 214 216 215 procedure TMainForm.FormDestroy(Sender: TObject); 217 216 begin 218 Scheduler.Free;217 MainScheduler.Free; 219 218 end; 220 219 … … 227 226 begin 228 227 try 229 Scheduler.MicroThreadsLock.Acquire;230 if Item.Index < Scheduler.MicroThreads.Count then231 with TMicroThread( Scheduler.MicroThreads[Item.Index]) do begin228 MainScheduler.MicroThreadsLock.Acquire; 229 if Item.Index < MainScheduler.MicroThreads.Count then 230 with TMicroThread(MainScheduler.MicroThreads[Item.Index]) do begin 232 231 Item.Caption := IntToStr(Id); 233 232 Item.SubItems.Add(Name); … … 240 239 end; 241 240 finally 242 Scheduler.MicroThreadsLock.Release;241 MainScheduler.MicroThreadsLock.Release; 243 242 end; 244 243 end; … … 246 245 procedure TMainForm.SpinEdit2Change(Sender: TObject); 247 246 begin 248 Scheduler.ThreadPoolSize := SpinEdit2.Value;247 MainScheduler.ThreadPoolSize := SpinEdit2.Value; 249 248 end; 250 249 … … 256 255 procedure TMainForm.TimerRedrawTimer(Sender: TObject); 257 256 begin 258 if ListView1.Items.Count <> Scheduler.MicroThreadCount then259 ListView1.Items.Count := Scheduler.MicroThreadCount;257 if ListView1.Items.Count <> MainScheduler.MicroThreadCount then 258 ListView1.Items.Count := MainScheduler.MicroThreadCount; 260 259 ListView1.Items[-1]; 261 260 ListView1.Refresh; 262 261 Label2.Caption := DateTimeToStr(NowPrecise) + ' ' + 263 262 FloatToStr(Frac(NowPrecise / OneSecond)); 264 Label9.Caption := IntToStr( Scheduler.ThreadPoolCount);265 Label10.Caption := IntToStr( Scheduler.MicroThreadCount);263 Label9.Caption := IntToStr(MainScheduler.ThreadPoolCount); 264 Label10.Caption := IntToStr(MainScheduler.MicroThreadCount); 266 265 end; 267 266 … … 271 270 ButtonAddWorkers.Click; 272 271 ButtonSchedulerStartStop.Click; 272 end; 273 274 procedure TMainForm.WorkerSubRoutine; 275 begin 276 MTSleep(1 * OneMillisecond); 273 277 end; 274 278 … … 287 291 // FloatToStr(ExecutionTime)); 288 292 Completion := I / Iterations; 289 // Sleep(1 * Id * OneMillisecond);293 //MTSleep(1 * Id * OneMillisecond); 290 294 Yield; 295 WorkerSubRoutine; 291 296 end; 292 297 end;
Note:
See TracChangeset
for help on using the changeset viewer.