Changeset 141
- Timestamp:
- Jan 24, 2011, 8:49:56 AM (14 years ago)
- Location:
- MicroThreading
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
MicroThreading/Demo/Demo.lpi
r140 r141 61 61 <EditorIndex Value="0"/> 62 62 <WindowIndex Value="0"/> 63 <TopLine Value=" 76"/>64 <CursorPos X=" 27" Y="92"/>63 <TopLine Value="176"/> 64 <CursorPos X="42" Y="177"/> 65 65 <UsageCount Value="39"/> 66 66 <Loaded Value="True"/> … … 72 72 <EditorIndex Value="10"/> 73 73 <WindowIndex Value="0"/> 74 <TopLine Value="1 75"/>75 <CursorPos X="2 8" Y="180"/>74 <TopLine Value="183"/> 75 <CursorPos X="20" Y="194"/> 76 76 <UsageCount Value="20"/> 77 77 <Loaded Value="True"/> … … 261 261 <TopLine Value="254"/> 262 262 <CursorPos X="12" Y="258"/> 263 <UsageCount Value="1 1"/>263 <UsageCount Value="12"/> 264 264 <Loaded Value="True"/> 265 265 </Unit25> … … 271 271 <TopLine Value="581"/> 272 272 <CursorPos X="11" Y="585"/> 273 <UsageCount Value="1 1"/>273 <UsageCount Value="12"/> 274 274 <Loaded Value="True"/> 275 275 </Unit26> … … 280 280 <TopLine Value="525"/> 281 281 <CursorPos X="11" Y="538"/> 282 <UsageCount Value="1 1"/>282 <UsageCount Value="12"/> 283 283 <Loaded Value="True"/> 284 284 </Unit27> … … 286 286 <JumpHistory Count="30" HistoryIndex="29"> 287 287 <Position1> 288 <Filename Value=" ../UMicroThreading.pas"/>289 <Caret Line=" 257" Column="44" TopLine="173"/>288 <Filename Value="UMainForm.pas"/> 289 <Caret Line="41" Column="24" TopLine="28"/> 290 290 </Position1> 291 291 <Position2> 292 <Filename Value=" ../UMicroThreading.pas"/>293 <Caret Line="1 41" Column="25" TopLine="125"/>292 <Filename Value="UMainForm.pas"/> 293 <Caret Line="182" Column="45" TopLine="169"/> 294 294 </Position2> 295 295 <Position3> 296 296 <Filename Value="../UMicroThreading.pas"/> 297 <Caret Line=" 127" Column="20" TopLine="125"/>297 <Caret Line="8" Column="57" TopLine="1"/> 298 298 </Position3> 299 299 <Position4> 300 <Filename Value=" UMainForm.pas"/>301 <Caret Line=" 191" Column="33" TopLine="171"/>300 <Filename Value="../UMicroThreading.pas"/> 301 <Caret Line="71" Column="20" TopLine="49"/> 302 302 </Position4> 303 303 <Position5> 304 <Filename Value=" UMainForm.pas"/>305 <Caret Line=" 182" Column="38" TopLine="159"/>304 <Filename Value="../UMicroThreading.pas"/> 305 <Caret Line="97" Column="24" TopLine="75"/> 306 306 </Position5> 307 307 <Position6> 308 <Filename Value=" UMainForm.pas"/>309 <Caret Line=" 41" Column="24" TopLine="28"/>308 <Filename Value="../UMicroThreading.pas"/> 309 <Caret Line="119" Column="38" TopLine="97"/> 310 310 </Position6> 311 311 <Position7> 312 312 <Filename Value="../UMicroThreading.pas"/> 313 <Caret Line="12 0" Column="38" TopLine="118"/>313 <Caret Line="126" Column="61" TopLine="104"/> 314 314 </Position7> 315 315 <Position8> 316 316 <Filename Value="../UMicroThreading.pas"/> 317 <Caret Line=" 67" Column="20" TopLine="66"/>317 <Caret Line="182" Column="34" TopLine="147"/> 318 318 </Position8> 319 319 <Position9> 320 <Filename Value=" UMainForm.pas"/>321 <Caret Line=" 41" Column="24" TopLine="28"/>320 <Filename Value="../UMicroThreading.pas"/> 321 <Caret Line="277" Column="45" TopLine="258"/> 322 322 </Position9> 323 323 <Position10> 324 <Filename Value=" UMainForm.pas"/>325 <Caret Line="1 82" Column="45" TopLine="169"/>324 <Filename Value="../UMicroThreading.pas"/> 325 <Caret Line="136" Column="14" TopLine="120"/> 326 326 </Position10> 327 327 <Position11> 328 <Filename Value=" ../UMicroThreading.pas"/>329 <Caret Line=" 8" Column="57" TopLine="1"/>328 <Filename Value="UMainForm.pas"/> 329 <Caret Line="191" Column="91" TopLine="173"/> 330 330 </Position11> 331 331 <Position12> 332 <Filename Value=" ../UMicroThreading.pas"/>333 <Caret Line=" 71" Column="20" TopLine="49"/>332 <Filename Value="UMainForm.pas"/> 333 <Caret Line="179" Column="40" TopLine="165"/> 334 334 </Position12> 335 335 <Position13> 336 336 <Filename Value="../UMicroThreading.pas"/> 337 <Caret Line=" 97" Column="24" TopLine="75"/>337 <Caret Line="193" Column="1" TopLine="181"/> 338 338 </Position13> 339 339 <Position14> 340 340 <Filename Value="../UMicroThreading.pas"/> 341 <Caret Line="11 9" Column="38" TopLine="97"/>341 <Caret Line="11" Column="56" TopLine="1"/> 342 342 </Position14> 343 343 <Position15> 344 344 <Filename Value="../UMicroThreading.pas"/> 345 <Caret Line="1 26" Column="61" TopLine="104"/>345 <Caret Line="15" Column="33" TopLine="1"/> 346 346 </Position15> 347 347 <Position16> 348 <Filename Value=" ../UMicroThreading.pas"/>349 <Caret Line=" 182" Column="34" TopLine="147"/>348 <Filename Value="UMainForm.pas"/> 349 <Caret Line="202" Column="91" TopLine="183"/> 350 350 </Position16> 351 351 <Position17> 352 352 <Filename Value="../UMicroThreading.pas"/> 353 <Caret Line=" 277" Column="45" TopLine="258"/>353 <Caret Line="42" Column="22" TopLine="22"/> 354 354 </Position17> 355 355 <Position18> 356 356 <Filename Value="../UMicroThreading.pas"/> 357 <Caret Line=" 136" Column="14" TopLine="120"/>357 <Caret Line="92" Column="1" TopLine="92"/> 358 358 </Position18> 359 359 <Position19> 360 360 <Filename Value="UMainForm.pas"/> 361 <Caret Line=" 191" Column="91" TopLine="173"/>361 <Caret Line="89" Column="19" TopLine="72"/> 362 362 </Position19> 363 363 <Position20> 364 <Filename Value=" UMainForm.pas"/>365 <Caret Line=" 179" Column="40" TopLine="165"/>364 <Filename Value="../UMicroThreading.pas"/> 365 <Caret Line="75" Column="22" TopLine="62"/> 366 366 </Position20> 367 367 <Position21> 368 <Filename Value=" ../UMicroThreading.pas"/>369 <Caret Line=" 193" Column="1" TopLine="181"/>368 <Filename Value="UMainForm.pas"/> 369 <Caret Line="89" Column="22" TopLine="76"/> 370 370 </Position21> 371 371 <Position22> 372 372 <Filename Value="../UMicroThreading.pas"/> 373 <Caret Line="1 1" Column="56" TopLine="1"/>373 <Caret Line="175" Column="9" TopLine="175"/> 374 374 </Position22> 375 375 <Position23> 376 376 <Filename Value="../UMicroThreading.pas"/> 377 <Caret Line=" 15" Column="33" TopLine="1"/>377 <Caret Line="79" Column="20" TopLine="64"/> 378 378 </Position23> 379 379 <Position24> 380 <Filename Value=" UMainForm.pas"/>381 <Caret Line=" 202" Column="91" TopLine="183"/>380 <Filename Value="../UMicroThreading.pas"/> 381 <Caret Line="172" Column="23" TopLine="170"/> 382 382 </Position24> 383 383 <Position25> 384 384 <Filename Value="../UMicroThreading.pas"/> 385 <Caret Line=" 42" Column="22" TopLine="22"/>385 <Caret Line="349" Column="1" TopLine="1"/> 386 386 </Position25> 387 387 <Position26> 388 388 <Filename Value="../UMicroThreading.pas"/> 389 <Caret Line=" 92" Column="1" TopLine="92"/>389 <Caret Line="192" Column="17" TopLine="179"/> 390 390 </Position26> 391 391 <Position27> 392 <Filename Value=" UMainForm.pas"/>393 <Caret Line=" 89" Column="19" TopLine="72"/>392 <Filename Value="../UMicroThreading.pas"/> 393 <Caret Line="11" Column="66" TopLine="1"/> 394 394 </Position27> 395 395 <Position28> 396 <Filename Value=" ../UMicroThreading.pas"/>397 <Caret Line=" 75" Column="22" TopLine="62"/>396 <Filename Value="UMainForm.pas"/> 397 <Caret Line="43" Column="1" TopLine="30"/> 398 398 </Position28> 399 399 <Position29> 400 400 <Filename Value="UMainForm.pas"/> 401 <Caret Line="8 9" Column="22" TopLine="76"/>401 <Caret Line="83" Column="1" TopLine="70"/> 402 402 </Position29> 403 403 <Position30> 404 <Filename Value=" ../UMicroThreading.pas"/>405 <Caret Line="1 75" Column="9" TopLine="175"/>404 <Filename Value="UMainForm.pas"/> 405 <Caret Line="154" Column="16" TopLine="141"/> 406 406 </Position30> 407 407 </JumpHistory> … … 439 439 <Item3> 440 440 <Source Value="umainform.pas"/> 441 <Line Value="5 6"/>441 <Line Value="55"/> 442 442 </Item3> 443 443 <Item4> -
MicroThreading/Demo/UMainForm.pas
r140 r141 41 41 Scheduler: TMicroThreadScheduler; 42 42 Test: TTest; 43 Terminate: Boolean; 44 end; 43 end; 45 44 46 45 var … … 73 72 Scheduler.FreeMicroThreadOnFinish := False; 74 73 Test := TTest.Create; 74 DoubleBuffered := True; 75 ListView1.DoubleBuffered := True; 75 76 end; 76 77 … … 78 79 var 79 80 I: Integer; 80 Executed: Integer;81 81 begin 82 82 if Button1.Caption = 'Start scheduler' then begin 83 83 Button1.Caption := 'Stop scheduler'; 84 Terminate := False;85 84 Scheduler.MicroThreads.Clear; 86 85 Memo1.Clear; 87 86 for I := 0 to 20 do 88 87 Scheduler.Add('Worker', Worker); 89 repeat 90 Executed := Scheduler.Execute(10); 91 Application.ProcessMessages; 92 if Executed = 0 then Sleep(1); 93 until (Scheduler.MicroThreadCount = 0) or Terminate; 88 Scheduler.Start; 94 89 end else begin 95 90 Button1.Caption := 'Start scheduler'; 96 Terminate := True;91 Scheduler.Stop; 97 92 end; 98 93 end; … … 158 153 procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction); 159 154 begin 160 Terminate := True;155 Scheduler.Stop; 161 156 end; 162 157 -
MicroThreading/UMicroThreading.pas
r140 r141 9 9 {$IFDEF Windows}Windows,{$ENDIF} 10 10 {$IFDEF Linux}BaseUnix, UnixUtil, Unix,{$ENDIF} 11 Classes, SysUtils, Contnrs, SyncObjs, DateUtils, Dialogs ;11 Classes, SysUtils, Contnrs, SyncObjs, DateUtils, Dialogs, Forms; 12 12 13 13 type … … 66 66 FExecuteCount: Integer; 67 67 FExecutedCount: Integer; 68 FTerminated: Boolean; 68 69 function GetMicroThreadCount: Integer; 69 70 procedure Yield(MicroThread: TMicroThread); … … 76 77 destructor Destroy; override; 77 78 function Execute(Count: Integer): Integer; 79 procedure Start; 80 procedure Stop; 78 81 property MicroThreadCount: Integer read GetMicroThreadCount; 79 82 property FreeMicroThreadOnFinish: Boolean read FFreeMicroThreadOnFinish … … 167 170 destructor TMicroThreadScheduler.Destroy; 168 171 begin 172 FTerminated := True; 169 173 ThreadPool.Free; 170 174 MicroThreads.Free; … … 179 183 Yield(nil); 180 184 Result := FExecutedCount; 185 end; 186 187 procedure TMicroThreadScheduler.Start; 188 var 189 Executed: Integer; 190 begin 191 FTerminated := False; 192 repeat 193 Executed := Execute(10); 194 Application.ProcessMessages; 195 if Executed = 0 then Sleep(1); 196 until FTerminated; 197 end; 198 199 procedure TMicroThreadScheduler.Stop; 200 begin 201 FTerminated := True; 181 202 end; 182 203
Note:
See TracChangeset
for help on using the changeset viewer.