Changeset 157
- Timestamp:
- Jan 28, 2011, 7:33:14 PM (14 years ago)
- Location:
- MicroThreading
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
MicroThreading/Demo/Demo.lpi
r156 r157 47 47 <TopLine Value="1"/> 48 48 <CursorPos X="34" Y="16"/> 49 <UsageCount Value="8 2"/>49 <UsageCount Value="86"/> 50 50 </Unit0> 51 51 <Unit1> … … 55 55 <ResourceBaseClass Value="Form"/> 56 56 <UnitName Value="UMainForm"/> 57 <EditorIndex Value=" 9"/>58 <WindowIndex Value="0"/> 59 <TopLine Value="2 70"/>60 <CursorPos X="1" Y="2 84"/>61 <UsageCount Value="8 2"/>57 <EditorIndex Value="4"/> 58 <WindowIndex Value="0"/> 59 <TopLine Value="247"/> 60 <CursorPos X="1" Y="261"/> 61 <UsageCount Value="86"/> 62 62 <Loaded Value="True"/> 63 63 <LoadedDesigner Value="True"/> … … 69 69 <EditorIndex Value="0"/> 70 70 <WindowIndex Value="0"/> 71 <TopLine Value=" 513"/>72 <CursorPos X=" 9" Y="525"/>73 <UsageCount Value="4 3"/>71 <TopLine Value="175"/> 72 <CursorPos X="1" Y="190"/> 73 <UsageCount Value="45"/> 74 74 <Loaded Value="True"/> 75 75 </Unit2> … … 142 142 <Unit11> 143 143 <Filename Value="/usr/share/fpcsrc/2.4.0/rtl/inc/systemh.inc"/> 144 <WindowIndex Value="0"/> 145 <TopLine Value="479"/> 146 <CursorPos X="3" Y="494"/> 147 <UsageCount Value="9"/> 144 <EditorIndex Value="1"/> 145 <WindowIndex Value="0"/> 146 <TopLine Value="896"/> 147 <CursorPos X="10" Y="911"/> 148 <UsageCount Value="10"/> 149 <Loaded Value="True"/> 148 150 </Unit11> 149 151 <Unit12> … … 192 194 <Unit18> 193 195 <Filename Value="/usr/share/fpcsrc/2.4.0/rtl/objpas/classes/classesh.inc"/> 194 <WindowIndex Value="0"/> 195 <TopLine Value="1823"/> 196 <CursorPos X="3" Y="1838"/> 196 <EditorIndex Value="2"/> 197 <WindowIndex Value="0"/> 198 <TopLine Value="1"/> 199 <CursorPos X="50" Y="9"/> 197 200 <UsageCount Value="10"/> 201 <Loaded Value="True"/> 198 202 </Unit18> 199 203 <Unit19> … … 257 261 <Unit27> 258 262 <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/win/wininc/redef.inc"/> 259 <EditorIndex Value="7"/>260 263 <WindowIndex Value="0"/> 261 264 <TopLine Value="739"/> 262 265 <CursorPos X="27" Y="752"/> 263 266 <UsageCount Value="17"/> 264 <Loaded Value="True"/>265 267 </Unit27> 266 268 <Unit28> 267 269 <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/packages/fcl-base/src/syncobjs.pp"/> 268 270 <UnitName Value="syncobjs"/> 269 <EditorIndex Value="2"/>270 271 <WindowIndex Value="0"/> 271 272 <TopLine Value="104"/> 272 273 <CursorPos X="28" Y="106"/> 273 274 <UsageCount Value="14"/> 274 <Loaded Value="True"/>275 275 </Unit28> 276 276 <Unit29> 277 277 <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/inc/threadh.inc"/> 278 <EditorIndex Value="3"/>279 278 <WindowIndex Value="0"/> 280 279 <TopLine Value="138"/> 281 280 <CursorPos X="11" Y="151"/> 282 281 <UsageCount Value="14"/> 283 <Loaded Value="True"/>284 282 </Unit29> 285 283 <Unit30> 286 284 <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/inc/thread.inc"/> 287 <EditorIndex Value="4"/>288 285 <WindowIndex Value="0"/> 289 286 <TopLine Value="199"/> 290 287 <CursorPos X="3" Y="202"/> 291 288 <UsageCount Value="14"/> 292 <Loaded Value="True"/>293 289 </Unit30> 294 290 <Unit31> 295 291 <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/win/sysosh.inc"/> 296 <EditorIndex Value="12"/>297 292 <WindowIndex Value="0"/> 298 293 <TopLine Value="8"/> 299 294 <CursorPos X="3" Y="33"/> 300 295 <UsageCount Value="14"/> 301 <Loaded Value="True"/>302 296 </Unit31> 303 297 <Unit32> 304 298 <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/objpas/classes/classesh.inc"/> 305 <EditorIndex Value="10"/>306 299 <WindowIndex Value="0"/> 307 300 <TopLine Value="302"/> 308 301 <CursorPos X="19" Y="319"/> 309 302 <UsageCount Value="20"/> 310 <Loaded Value="True"/>311 303 </Unit32> 312 304 <Unit33> … … 396 388 <Unit45> 397 389 <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/lcl/interfaces/win32/win32object.inc"/> 398 <EditorIndex Value="1"/>399 390 <WindowIndex Value="0"/> 400 391 <TopLine Value="387"/> 401 392 <CursorPos X="1" Y="400"/> 402 393 <UsageCount Value="11"/> 403 <Loaded Value="True"/>404 394 </Unit45> 405 395 <Unit46> … … 420 410 <Filename Value="../UPlatform.pas"/> 421 411 <UnitName Value="UPlatform"/> 422 <EditorIndex Value=" 6"/>412 <EditorIndex Value="3"/> 423 413 <WindowIndex Value="0"/> 424 414 <TopLine Value="23"/> 425 415 <CursorPos X="31" Y="38"/> 426 <UsageCount Value="2 3"/>416 <UsageCount Value="25"/> 427 417 <Loaded Value="True"/> 428 418 </Unit48> … … 487 477 <Unit57> 488 478 <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/objpas/classes/lists.inc"/> 489 <EditorIndex Value="11"/>490 479 <WindowIndex Value="0"/> 491 480 <TopLine Value="909"/> 492 481 <CursorPos X="26" Y="917"/> 493 482 <UsageCount Value="15"/> 494 <Loaded Value="True"/>495 483 </Unit57> 496 484 <Unit58> … … 535 523 <Unit63> 536 524 <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/objpas/sysutils/sysutilh.inc"/> 537 <EditorIndex Value="8"/>538 525 <WindowIndex Value="0"/> 539 526 <TopLine Value="1"/> 540 527 <CursorPos X="55" Y="4"/> 541 528 <UsageCount Value="16"/> 542 <Loaded Value="True"/>543 529 </Unit63> 544 530 <Unit64> 545 531 <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/lcl/controls.pp"/> 546 532 <UnitName Value="Controls"/> 547 <EditorIndex Value="5"/>548 533 <WindowIndex Value="0"/> 549 534 <TopLine Value="2660"/> 550 535 <CursorPos X="1" Y="2673"/> 551 536 <UsageCount Value="15"/> 552 <Loaded Value="True"/>553 537 </Unit64> 554 538 </Units> 555 <JumpHistory Count="30" HistoryIndex="2 8">539 <JumpHistory Count="30" HistoryIndex="29"> 556 540 <Position1> 557 541 <Filename Value="../UMicroThreading.pas"/> 558 <Caret Line=" 773" Column="1" TopLine="760"/>542 <Caret Line="531" Column="1" TopLine="515"/> 559 543 </Position1> 560 544 <Position2> 561 545 <Filename Value="../UMicroThreading.pas"/> 562 <Caret Line=" 774" Column="1" TopLine="760"/>546 <Caret Line="532" Column="1" TopLine="515"/> 563 547 </Position2> 564 548 <Position3> 565 549 <Filename Value="../UMicroThreading.pas"/> 566 <Caret Line=" 772" Column="1" TopLine="760"/>550 <Caret Line="954" Column="1" TopLine="939"/> 567 551 </Position3> 568 552 <Position4> 569 553 <Filename Value="../UMicroThreading.pas"/> 570 <Caret Line=" 773" Column="1" TopLine="760"/>554 <Caret Line="822" Column="1" TopLine="807"/> 571 555 </Position4> 572 556 <Position5> 573 557 <Filename Value="../UMicroThreading.pas"/> 574 <Caret Line=" 774" Column="1" TopLine="760"/>558 <Caret Line="824" Column="1" TopLine="807"/> 575 559 </Position5> 576 560 <Position6> 577 561 <Filename Value="../UMicroThreading.pas"/> 578 <Caret Line=" 772" Column="1" TopLine="760"/>562 <Caret Line="955" Column="1" TopLine="940"/> 579 563 </Position6> 580 564 <Position7> 581 <Filename Value=" ../UMicroThreading.pas"/>582 <Caret Line=" 773" Column="1" TopLine="760"/>565 <Filename Value="UMainForm.pas"/> 566 <Caret Line="262" Column="1" TopLine="247"/> 583 567 </Position7> 584 568 <Position8> 585 <Filename Value=" ../UMicroThreading.pas"/>586 <Caret Line=" 774" Column="1" TopLine="760"/>569 <Filename Value="UMainForm.pas"/> 570 <Caret Line="261" Column="1" TopLine="247"/> 587 571 </Position8> 588 572 <Position9> 589 573 <Filename Value="../UMicroThreading.pas"/> 590 <Caret Line=" 772" Column="1" TopLine="760"/>574 <Caret Line="816" Column="1" TopLine="801"/> 591 575 </Position9> 592 576 <Position10> 593 577 <Filename Value="../UMicroThreading.pas"/> 594 <Caret Line="77 3" Column="1" TopLine="760"/>578 <Caret Line="777" Column="1" TopLine="756"/> 595 579 </Position10> 596 580 <Position11> 597 581 <Filename Value="../UMicroThreading.pas"/> 598 <Caret Line="7 74" Column="1" TopLine="760"/>582 <Caret Line="760" Column="1" TopLine="754"/> 599 583 </Position11> 600 584 <Position12> 601 585 <Filename Value="../UMicroThreading.pas"/> 602 <Caret Line="7 72" Column="1" TopLine="760"/>586 <Caret Line="762" Column="1" TopLine="754"/> 603 587 </Position12> 604 588 <Position13> 605 589 <Filename Value="../UMicroThreading.pas"/> 606 <Caret Line="7 73" Column="1" TopLine="760"/>590 <Caret Line="763" Column="1" TopLine="754"/> 607 591 </Position13> 608 592 <Position14> 609 593 <Filename Value="../UMicroThreading.pas"/> 610 <Caret Line="7 74" Column="1" TopLine="760"/>594 <Caret Line="764" Column="1" TopLine="754"/> 611 595 </Position14> 612 596 <Position15> 613 597 <Filename Value="../UMicroThreading.pas"/> 614 <Caret Line="7 72" Column="1" TopLine="760"/>598 <Caret Line="768" Column="2" TopLine="754"/> 615 599 </Position15> 616 600 <Position16> 617 601 <Filename Value="../UMicroThreading.pas"/> 618 <Caret Line="7 73" Column="1" TopLine="760"/>602 <Caret Line="767" Column="1" TopLine="754"/> 619 603 </Position16> 620 604 <Position17> 621 605 <Filename Value="../UMicroThreading.pas"/> 622 <Caret Line="7 74" Column="1" TopLine="760"/>606 <Caret Line="768" Column="1" TopLine="754"/> 623 607 </Position17> 624 608 <Position18> 625 609 <Filename Value="../UMicroThreading.pas"/> 626 <Caret Line="7 72" Column="1" TopLine="760"/>610 <Caret Line="769" Column="1" TopLine="754"/> 627 611 </Position18> 628 612 <Position19> 629 613 <Filename Value="../UMicroThreading.pas"/> 630 <Caret Line="7 73" Column="1" TopLine="760"/>614 <Caret Line="768" Column="1" TopLine="754"/> 631 615 </Position19> 632 616 <Position20> 633 617 <Filename Value="../UMicroThreading.pas"/> 634 <Caret Line="77 4" Column="1" TopLine="760"/>618 <Caret Line="770" Column="22" TopLine="754"/> 635 619 </Position20> 636 620 <Position21> 637 621 <Filename Value="../UMicroThreading.pas"/> 638 <Caret Line="7 72" Column="1" TopLine="760"/>622 <Caret Line="760" Column="1" TopLine="754"/> 639 623 </Position21> 640 624 <Position22> 641 625 <Filename Value="../UMicroThreading.pas"/> 642 <Caret Line="7 73" Column="1" TopLine="760"/>626 <Caret Line="762" Column="1" TopLine="754"/> 643 627 </Position22> 644 628 <Position23> 645 629 <Filename Value="../UMicroThreading.pas"/> 646 <Caret Line="7 74" Column="1" TopLine="760"/>630 <Caret Line="767" Column="1" TopLine="754"/> 647 631 </Position23> 648 632 <Position24> 649 633 <Filename Value="../UMicroThreading.pas"/> 650 <Caret Line=" 810" Column="35" TopLine="796"/>634 <Caret Line="768" Column="1" TopLine="754"/> 651 635 </Position24> 652 636 <Position25> 653 <Filename Value="../ ../../../Programy/Lazarus/0.9.31_2.4.3/lcl/interfaces/win32/win32object.inc"/>654 <Caret Line=" 400" Column="1" TopLine="387"/>637 <Filename Value="../UMicroThreading.pas"/> 638 <Caret Line="770" Column="1" TopLine="754"/> 655 639 </Position25> 656 640 <Position26> 657 641 <Filename Value="../UMicroThreading.pas"/> 658 <Caret Line=" 524" Column="9" TopLine="513"/>642 <Caret Line="772" Column="1" TopLine="754"/> 659 643 </Position26> 660 644 <Position27> 661 645 <Filename Value="../UMicroThreading.pas"/> 662 <Caret Line=" 523" Column="1" TopLine="513"/>646 <Caret Line="776" Column="1" TopLine="754"/> 663 647 </Position27> 664 648 <Position28> 665 649 <Filename Value="../UMicroThreading.pas"/> 666 <Caret Line=" 524" Column="1" TopLine="513"/>650 <Caret Line="777" Column="1" TopLine="754"/> 667 651 </Position28> 668 652 <Position29> 669 653 <Filename Value="../UMicroThreading.pas"/> 670 <Caret Line=" 526" Column="1" TopLine="513"/>654 <Caret Line="778" Column="1" TopLine="754"/> 671 655 </Position29> 672 656 <Position30> 673 <Filename Value="../ ../../../Programy/Lazarus/0.9.31_2.4.3/lcl/interfaces/win32/win32object.inc"/>674 <Caret Line=" 400" Column="1" TopLine="387"/>657 <Filename Value="../UMicroThreading.pas"/> 658 <Caret Line="782" Column="1" TopLine="782"/> 675 659 </Position30> 676 660 </JumpHistory> … … 712 696 </CompilerOptions> 713 697 <Debugging> 714 <BreakPoints Count="1">715 <Item1>716 <Source Value="../UMicroThreading.pas"/>717 <Line Value="523"/>718 </Item1>719 </BreakPoints>720 698 <Watches Count="2"> 721 699 <Item1> -
MicroThreading/Demo/UMainForm.lfm
r156 r157 22 22 object TabSheet2: TTabSheet 23 23 Caption = 'Scheduler state' 24 ClientHeight = 49 325 ClientWidth = 79 424 ClientHeight = 492 25 ClientWidth = 798 26 26 object ListView1: TListView 27 27 Left = 222 28 Height = 4 6028 Height = 459 29 29 Top = 24 30 Width = 5 6730 Width = 571 31 31 Anchors = [akTop, akLeft, akRight, akBottom] 32 32 Columns = < … … 76 76 Height = 14 77 77 Top = 7 78 Width = 7 479 Caption = 'Microthread list'78 Width = 76 79 Caption = 'Microthreads:' 80 80 ParentColor = False 81 81 end … … 86 86 Width = 205 87 87 Caption = 'State' 88 ClientHeight = 6 388 ClientHeight = 66 89 89 ClientWidth = 201 90 90 TabOrder = 1 … … 93 93 Height = 14 94 94 Top = 4 95 Width = 1 1795 Width = 135 96 96 Caption = 'Logical processor count:' 97 97 ParentColor = False … … 109 109 Height = 14 110 110 Top = 20 111 Width = 69111 Width = 78 112 112 Caption = 'Thread count:' 113 113 ParentColor = False … … 117 117 Height = 14 118 118 Top = 36 119 Width = 95119 Width = 107 120 120 Caption = 'Micro thread count:' 121 121 ParentColor = False … … 144 144 Width = 206 145 145 Caption = 'Control' 146 ClientHeight = 1 08146 ClientHeight = 111 147 147 ClientWidth = 202 148 148 TabOrder = 2 … … 160 160 Height = 14 161 161 Top = 46 162 Width = 69162 Width = 78 163 163 Caption = 'Thread count:' 164 164 ParentColor = False … … 174 174 object CheckBoxUseMainThread: TCheckBox 175 175 Left = 10 176 Height = 17176 Height = 20 177 177 Top = 64 178 Width = 98178 Width = 112 179 179 Caption = 'Use main thread' 180 180 OnChange = CheckBoxUseMainThreadChange … … 182 182 end 183 183 end 184 object ListView2: TListView 185 Left = 6 186 Height = 236 187 Top = 247 188 Width = 206 189 Anchors = [akTop, akLeft, akBottom] 190 Columns = < 191 item 192 Caption = 'Id' 193 end 194 item 195 Caption = 'State' 196 Width = 135 197 end> 198 OwnerData = True 199 TabOrder = 3 200 ViewStyle = vsReport 201 OnData = ListView2Data 202 end 203 object Label13: TLabel 204 Left = 7 205 Height = 14 206 Top = 233 207 Width = 50 208 Caption = 'Threads:' 209 ParentColor = False 210 end 184 211 end 185 212 object TabSheet1: TTabSheet 186 213 Caption = 'Job control' 187 ClientHeight = 49 3188 ClientWidth = 79 4214 ClientHeight = 492 215 ClientWidth = 798 189 216 object ButtonAddWorkers: TButton 190 217 Left = 10 … … 263 290 object TabSheet3: TTabSheet 264 291 Caption = 'Testing' 265 ClientHeight = 49 3266 ClientWidth = 7 53292 ClientHeight = 492 293 ClientWidth = 798 267 294 object ButtonShowThreadId: TButton 268 295 Left = 14 -
MicroThreading/Demo/UMainForm.pas
r156 r157 28 28 Label11: TLabel; 29 29 Label12: TLabel; 30 Label13: TLabel; 30 31 Label2: TLabel; 31 32 Label3: TLabel; … … 37 38 Label9: TLabel; 38 39 ListView1: TListView; 40 ListView2: TListView; 39 41 Memo1: TMemo; 40 42 PageControl1: TPageControl; … … 58 60 procedure FormShow(Sender: TObject); 59 61 procedure ListView1Data(Sender: TObject; Item: TListItem); 62 procedure ListView2Data(Sender: TObject; Item: TListItem); 60 63 procedure SpinEdit2Change(Sender: TObject); 61 64 procedure SpinEdit3Change(Sender: TObject); … … 240 243 end; 241 244 245 procedure TMainForm.ListView2Data(Sender: TObject; Item: TListItem); 246 begin 247 if Item.Index < MainScheduler.ThreadPoolCount then 248 try 249 MainScheduler.ThreadPoolLock.Acquire; 250 with TMicroThreadThread(MainScheduler.ThreadPool[Item.Index]) do begin 251 Item.Caption := IntToStr(ThreadID); 252 Item.SubItems.Add(MicroThreadThreadStateText[State]); 253 end; 254 finally 255 MainScheduler.ThreadPoolLock.Release; 256 end; 257 end; 258 242 259 procedure TMainForm.SpinEdit2Change(Sender: TObject); 243 260 begin … … 256 273 ListView1.Items[-1]; 257 274 ListView1.Refresh; 275 276 if ListView2.Items.Count <> MainScheduler.ThreadPoolCount then 277 ListView2.Items.Count := MainScheduler.ThreadPoolCount; 278 ListView2.Items[-1]; 279 ListView2.Refresh; 280 258 281 Label2.Caption := DateTimeToStr(NowPrecise) + ' ' + 259 282 FloatToStr(Frac(NowPrecise / OneSecond)); -
MicroThreading/UMicroThreading.pas
r156 r157 119 119 end; 120 120 121 TMicroThreadThreadState = (ttsReady, ttsRunning, ttsTerminated); 122 121 123 { TMicroThreadThread } 122 124 123 125 TMicroThreadThread = class(TThread) 124 126 Manager: TMicroThreadManager; 125 ExecuteTerminated: Boolean;127 State: TMicroThreadThreadState; 126 128 procedure Execute; override; 127 129 constructor Create(CreateSuspended: Boolean; … … 140 142 FExecuteCount: Integer; 141 143 FExecutedCount: Integer; 142 FTerminated: Boolean;143 144 FCurrentMicroThread: TMicroThread; 144 145 FScheduler: TMicroThreadScheduler; … … 187 188 procedure Start; 188 189 procedure Stop; 189 procedure PoolThreadTerminated(Sender: TObject);190 190 procedure UpdateThreadPoolSize; 191 191 procedure MainThreadStart(Sender: TObject); … … 197 197 destructor Destroy; override; 198 198 property ThreadPool: TObjectList read FThreadPool; 199 property ThreadPoolLock: TCriticalSection read FThreadPoolLock; 199 200 property ThreadPoolSize: Integer read GetThreadPoolSize 200 201 write SetThreadPoolSize; … … 216 217 MicroThreadBlockStateText: array[TMicroThreadBlockState] of string = ('None', 217 218 'Sleeping', 'WaitFor', 'Terminating', 'Terminated'); 219 MicroThreadThreadStateText: array[TMicroThreadThreadState] of string = ( 220 'Ready', 'Running', 'Terminated'); 218 221 219 222 function GetCurrentMicroThread: TMicroThread; … … 503 506 try 504 507 repeat 505 ExecutedCount := Manager.Execute(100000); 508 State := ttsRunning; 509 ExecutedCount := Manager.Execute(10); 510 State := ttsReady; 506 511 if ExecutedCount = 0 then Sleep(1); 507 512 until Terminated; … … 516 521 begin 517 522 inherited; 518 ExecuteTerminated := False;523 State := ttsReady; 519 524 Manager := TMicroThreadManager.Create; 520 525 end; … … 522 527 destructor TMicroThreadThread.Destroy; 523 528 begin 524 Terminate;525 repeat526 Sleep(1);527 until ExecuteTerminated;528 529 529 Manager.Free; 530 530 inherited Destroy; … … 758 758 begin 759 759 FState := ssTerminating; 760 // Wait for all thread managers to finish 760 761 try 761 762 FThreadPoolLock.Acquire; … … 763 764 TMicroThreadThread(FThreadPool[I]).Terminate; 764 765 end; 766 for I := 0 to FThreadPool.Count - 1 do begin 767 TMicroThreadThread(FThreadPool[I]).WaitFor; 768 end; 769 FThreadPool.Clear; 765 770 finally 766 771 FThreadPoolLock.Release; 767 772 end; 768 773 769 // Wait for all thread managers to finish770 774 repeat 771 775 Application.ProcessMessages; 772 776 Sleep(1); 773 until FMainThreadTerminated and (ThreadPoolCount = 0);777 until FMainThreadTerminated or (not FUseMainThread); 774 778 FState := ssStopped; 775 end;776 777 procedure TMicroThreadScheduler.PoolThreadTerminated(Sender: TObject);778 var779 ThreadIndex: Integer;780 begin781 TMicroThreadThread(Sender).ExecuteTerminated := True;782 try783 FThreadPoolLock.Acquire;784 FThreadPool.OwnsObjects := False;785 ThreadIndex := FThreadPool.IndexOf(Sender);786 if ThreadIndex = -1 then787 raise Exception.Create('Trying to free thread not found in thread pool');788 FThreadPool.Delete(ThreadIndex);789 finally790 FThreadPool.OwnsObjects := True;791 FThreadPoolLock.Release;792 end;793 779 end; 794 780 … … 806 792 NewThread.Manager.FId := FThreadPool.Count + 1; 807 793 NewThread.Manager.FThread := NewThread; 808 NewThread.OnTerminate := PoolThreadTerminated;809 NewThread.FreeOnTerminate := True;794 //NewThread.OnTerminate := PoolThreadTerminated; 795 NewThread.FreeOnTerminate := False; 810 796 ThreadPool.Add(NewThread); 811 797 NewThread.Resume; … … 813 799 end else begin 814 800 while FThreadPool.Count > FThreadPoolSize do begin 801 TMicroThreadThread(FThreadPool[FThreadPool.Count - 1]).Terminate; 802 TMicroThreadThread(FThreadPool[FThreadPool.Count - 1]).WaitFor; 815 803 FThreadPool.Delete(FThreadPool.Count - 1); 816 804 end; … … 946 934 947 935 procedure TMicroThreadScheduler.SetThreadPoolSize(const AValue: Integer); 948 var949 I: Integer;950 NewThread: TMicroThreadThread;951 936 begin 952 937 FThreadPoolSize := AValue;
Note:
See TracChangeset
for help on using the changeset viewer.