Changeset 153 for MicroThreading


Ignore:
Timestamp:
Jan 27, 2011, 10:56:06 AM (13 years ago)
Author:
george
Message:
  • Added: Synchronize method.
Location:
MicroThreading
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • MicroThreading/Demo/Demo.lpi

    r152 r153  
    3939      </Item2>
    4040    </RequiredPackages>
    41     <Units Count="61">
     41    <Units Count="62">
    4242      <Unit0>
    4343        <Filename Value="Demo.lpr"/>
     
    4747        <TopLine Value="1"/>
    4848        <CursorPos X="5" Y="9"/>
    49         <UsageCount Value="67"/>
     49        <UsageCount Value="68"/>
    5050      </Unit0>
    5151      <Unit1>
     
    5757        <EditorIndex Value="0"/>
    5858        <WindowIndex Value="0"/>
    59         <TopLine Value="268"/>
    60         <CursorPos X="1" Y="288"/>
    61         <UsageCount Value="67"/>
     59        <TopLine Value="1"/>
     60        <CursorPos X="15" Y="67"/>
     61        <UsageCount Value="68"/>
    6262        <Loaded Value="True"/>
    6363        <LoadedDesigner Value="True"/>
     
    6767        <UnitName Value="UMicroThreading"/>
    6868        <IsVisibleTab Value="True"/>
    69         <EditorIndex Value="2"/>
    70         <WindowIndex Value="0"/>
    71         <TopLine Value="272"/>
    72         <CursorPos X="23" Y="288"/>
     69        <EditorIndex Value="1"/>
     70        <WindowIndex Value="0"/>
     71        <TopLine Value="446"/>
     72        <CursorPos X="6" Y="450"/>
    7373        <UsageCount Value="37"/>
    7474        <Loaded Value="True"/>
     
    293293      <Unit32>
    294294        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/objpas/classes/classesh.inc"/>
    295         <EditorIndex Value="6"/>
    296         <WindowIndex Value="0"/>
    297         <TopLine Value="1466"/>
    298         <CursorPos X="15" Y="1479"/>
     295        <EditorIndex Value="5"/>
     296        <WindowIndex Value="0"/>
     297        <TopLine Value="1467"/>
     298        <CursorPos X="5" Y="1488"/>
    299299        <UsageCount Value="18"/>
    300300        <Loaded Value="True"/>
     
    302302      <Unit33>
    303303        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/win/tthread.inc"/>
    304         <EditorIndex Value="7"/>
     304        <EditorIndex Value="6"/>
    305305        <WindowIndex Value="0"/>
    306306        <TopLine Value="52"/>
    307         <CursorPos X="23" Y="55"/>
     307        <CursorPos X="25" Y="65"/>
    308308        <UsageCount Value="15"/>
    309309        <Loaded Value="True"/>
     
    325325      <Unit36>
    326326        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/objpas/classes/classes.inc"/>
    327         <EditorIndex Value="8"/>
    328         <WindowIndex Value="0"/>
    329         <TopLine Value="85"/>
    330         <CursorPos X="21" Y="107"/>
     327        <EditorIndex Value="7"/>
     328        <WindowIndex Value="0"/>
     329        <TopLine Value="124"/>
     330        <CursorPos X="3" Y="126"/>
    331331        <UsageCount Value="18"/>
    332332        <Loaded Value="True"/>
     
    341341      <Unit38>
    342342        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/objpas/sysutils/osutilsh.inc"/>
    343         <EditorIndex Value="3"/>
     343        <EditorIndex Value="2"/>
    344344        <WindowIndex Value="0"/>
    345345        <TopLine Value="14"/>
     
    414414        <Filename Value="../UPlatform.pas"/>
    415415        <UnitName Value="UPlatform"/>
    416         <EditorIndex Value="10"/>
     416        <EditorIndex Value="9"/>
    417417        <WindowIndex Value="0"/>
    418418        <TopLine Value="1"/>
    419         <CursorPos X="24" Y="9"/>
     419        <CursorPos X="14" Y="1"/>
    420420        <UsageCount Value="17"/>
    421421        <Loaded Value="True"/>
     
    481481      <Unit57>
    482482        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/objpas/classes/lists.inc"/>
    483         <EditorIndex Value="9"/>
     483        <EditorIndex Value="8"/>
    484484        <WindowIndex Value="0"/>
    485485        <TopLine Value="590"/>
    486486        <CursorPos X="14" Y="594"/>
    487         <UsageCount Value="12"/>
     487        <UsageCount Value="13"/>
    488488        <Loaded Value="True"/>
    489489      </Unit57>
    490490      <Unit58>
    491491        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/lcl/interfaces/win32/win32callback.inc"/>
    492         <EditorIndex Value="5"/>
     492        <EditorIndex Value="4"/>
    493493        <WindowIndex Value="0"/>
    494494        <TopLine Value="1086"/>
    495495        <CursorPos X="1" Y="1099"/>
    496         <UsageCount Value="12"/>
     496        <UsageCount Value="13"/>
    497497        <Loaded Value="True"/>
    498498      </Unit58>
     
    500500        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/lcl/extctrls.pp"/>
    501501        <UnitName Value="ExtCtrls"/>
    502         <EditorIndex Value="1"/>
    503502        <WindowIndex Value="0"/>
    504503        <TopLine Value="357"/>
    505504        <CursorPos X="3" Y="370"/>
    506         <UsageCount Value="12"/>
    507         <Loaded Value="True"/>
     505        <UsageCount Value="11"/>
    508506      </Unit59>
    509507      <Unit60>
    510508        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/lcl/customtimer.pas"/>
    511509        <UnitName Value="CustomTimer"/>
    512         <EditorIndex Value="4"/>
     510        <EditorIndex Value="3"/>
    513511        <WindowIndex Value="0"/>
    514512        <TopLine Value="40"/>
    515513        <CursorPos X="17" Y="53"/>
    516         <UsageCount Value="11"/>
     514        <UsageCount Value="12"/>
    517515        <Loaded Value="True"/>
    518516      </Unit60>
     517      <Unit61>
     518        <Filename Value="../ReadMe.txt"/>
     519        <EditorIndex Value="10"/>
     520        <WindowIndex Value="0"/>
     521        <TopLine Value="1"/>
     522        <CursorPos X="17" Y="14"/>
     523        <UsageCount Value="10"/>
     524        <Loaded Value="True"/>
     525        <DefaultSyntaxHighlighter Value="None"/>
     526      </Unit61>
    519527    </Units>
    520     <JumpHistory Count="30" HistoryIndex="28">
     528    <JumpHistory Count="30" HistoryIndex="29">
    521529      <Position1>
    522530        <Filename Value="../UMicroThreading.pas"/>
    523         <Caret Line="299" Column="1" TopLine="280"/>
     531        <Caret Line="279" Column="19" TopLine="267"/>
    524532      </Position1>
    525533      <Position2>
    526534        <Filename Value="../UMicroThreading.pas"/>
    527         <Caret Line="300" Column="1" TopLine="280"/>
     535        <Caret Line="295" Column="1" TopLine="270"/>
    528536      </Position2>
    529537      <Position3>
    530538        <Filename Value="../UMicroThreading.pas"/>
    531         <Caret Line="301" Column="1" TopLine="280"/>
     539        <Caret Line="289" Column="1" TopLine="270"/>
    532540      </Position3>
    533541      <Position4>
    534542        <Filename Value="../UMicroThreading.pas"/>
    535         <Caret Line="302" Column="1" TopLine="283"/>
     543        <Caret Line="290" Column="1" TopLine="270"/>
    536544      </Position4>
    537545      <Position5>
    538546        <Filename Value="../UMicroThreading.pas"/>
    539         <Caret Line="465" Column="1" TopLine="452"/>
     547        <Caret Line="291" Column="1" TopLine="270"/>
    540548      </Position5>
    541549      <Position6>
    542550        <Filename Value="../UMicroThreading.pas"/>
    543         <Caret Line="468" Column="1" TopLine="452"/>
     551        <Caret Line="292" Column="1" TopLine="270"/>
    544552      </Position6>
    545553      <Position7>
    546554        <Filename Value="../UMicroThreading.pas"/>
    547         <Caret Line="469" Column="1" TopLine="452"/>
     555        <Caret Line="598" Column="50" TopLine="587"/>
    548556      </Position7>
    549557      <Position8>
    550558        <Filename Value="../UMicroThreading.pas"/>
    551         <Caret Line="470" Column="1" TopLine="452"/>
     559        <Caret Line="291" Column="40" TopLine="278"/>
    552560      </Position8>
    553561      <Position9>
    554562        <Filename Value="../UMicroThreading.pas"/>
    555         <Caret Line="226" Column="1" TopLine="213"/>
     563        <Caret Line="280" Column="1" TopLine="272"/>
    556564      </Position9>
    557565      <Position10>
    558566        <Filename Value="../UMicroThreading.pas"/>
    559         <Caret Line="304" Column="1" TopLine="291"/>
     567        <Caret Line="288" Column="26" TopLine="272"/>
    560568      </Position10>
    561569      <Position11>
    562570        <Filename Value="../UMicroThreading.pas"/>
    563         <Caret Line="312" Column="1" TopLine="291"/>
     571        <Caret Line="285" Column="35" TopLine="272"/>
    564572      </Position11>
    565573      <Position12>
    566574        <Filename Value="../UMicroThreading.pas"/>
    567         <Caret Line="329" Column="1" TopLine="316"/>
     575        <Caret Line="288" Column="1" TopLine="272"/>
    568576      </Position12>
    569577      <Position13>
    570578        <Filename Value="../UMicroThreading.pas"/>
    571         <Caret Line="227" Column="1" TopLine="214"/>
     579        <Caret Line="289" Column="1" TopLine="272"/>
    572580      </Position13>
    573581      <Position14>
    574582        <Filename Value="../UMicroThreading.pas"/>
    575         <Caret Line="228" Column="1" TopLine="214"/>
     583        <Caret Line="290" Column="1" TopLine="272"/>
    576584      </Position14>
    577585      <Position15>
    578586        <Filename Value="../UMicroThreading.pas"/>
    579         <Caret Line="351" Column="1" TopLine="338"/>
     587        <Caret Line="291" Column="1" TopLine="272"/>
    580588      </Position15>
    581589      <Position16>
    582590        <Filename Value="../UMicroThreading.pas"/>
    583         <Caret Line="352" Column="1" TopLine="338"/>
     591        <Caret Line="292" Column="1" TopLine="272"/>
    584592      </Position16>
    585593      <Position17>
    586594        <Filename Value="../UMicroThreading.pas"/>
    587         <Caret Line="350" Column="1" TopLine="338"/>
     595        <Caret Line="293" Column="1" TopLine="272"/>
    588596      </Position17>
    589597      <Position18>
    590598        <Filename Value="../UMicroThreading.pas"/>
    591         <Caret Line="351" Column="35" TopLine="338"/>
     599        <Caret Line="296" Column="1" TopLine="274"/>
    592600      </Position18>
    593601      <Position19>
    594602        <Filename Value="../UMicroThreading.pas"/>
    595         <Caret Line="279" Column="19" TopLine="267"/>
     603        <Caret Line="297" Column="1" TopLine="275"/>
    596604      </Position19>
    597605      <Position20>
    598606        <Filename Value="../UMicroThreading.pas"/>
    599         <Caret Line="295" Column="1" TopLine="270"/>
     607        <Caret Line="298" Column="1" TopLine="276"/>
    600608      </Position20>
    601609      <Position21>
    602610        <Filename Value="../UMicroThreading.pas"/>
    603         <Caret Line="289" Column="1" TopLine="270"/>
     611        <Caret Line="299" Column="1" TopLine="277"/>
    604612      </Position21>
    605613      <Position22>
    606614        <Filename Value="../UMicroThreading.pas"/>
    607         <Caret Line="290" Column="1" TopLine="270"/>
     615        <Caret Line="471" Column="1" TopLine="458"/>
    608616      </Position22>
    609617      <Position23>
    610618        <Filename Value="../UMicroThreading.pas"/>
    611         <Caret Line="291" Column="1" TopLine="270"/>
     619        <Caret Line="285" Column="32" TopLine="275"/>
    612620      </Position23>
    613621      <Position24>
    614         <Filename Value="../UMicroThreading.pas"/>
    615         <Caret Line="292" Column="1" TopLine="270"/>
     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"/>
    616624      </Position24>
    617625      <Position25>
    618626        <Filename Value="../UMicroThreading.pas"/>
    619         <Caret Line="598" Column="50" TopLine="587"/>
     627        <Caret Line="71" Column="5" TopLine="55"/>
    620628      </Position25>
    621629      <Position26>
    622630        <Filename Value="../UMicroThreading.pas"/>
    623         <Caret Line="291" Column="40" TopLine="278"/>
     631        <Caret Line="125" Column="1" TopLine="110"/>
    624632      </Position26>
    625633      <Position27>
    626         <Filename Value="../UMicroThreading.pas"/>
    627         <Caret Line="280" Column="1" TopLine="272"/>
     634        <Filename Value="UMainForm.pas"/>
     635        <Caret Line="68" Column="29" TopLine="54"/>
    628636      </Position27>
    629637      <Position28>
    630638        <Filename Value="../UMicroThreading.pas"/>
    631         <Caret Line="288" Column="26" TopLine="272"/>
     639        <Caret Line="566" Column="20" TopLine="561"/>
    632640      </Position28>
    633641      <Position29>
    634642        <Filename Value="../UMicroThreading.pas"/>
    635         <Caret Line="285" Column="35" TopLine="272"/>
     643        <Caret Line="567" Column="23" TopLine="554"/>
    636644      </Position29>
    637645      <Position30>
    638646        <Filename Value="../UMicroThreading.pas"/>
    639         <Caret Line="397" Column="18" TopLine="393"/>
     647        <Caret Line="579" Column="51" TopLine="560"/>
    640648      </Position30>
    641649    </JumpHistory>
     
    655663        <RangeChecks Value="True"/>
    656664        <OverflowChecks Value="True"/>
     665        <StackChecks Value="True"/>
    657666      </Checks>
    658667    </CodeGeneration>
     
    675684  </CompilerOptions>
    676685  <Debugging>
    677     <BreakPoints Count="4">
    678       <Item1>
    679         <Source Value="../UMicroThreading.pas"/>
    680         <Line Value="296"/>
    681       </Item1>
    682       <Item2>
    683         <Source Value="../UMicroThreading.pas"/>
    684         <Line Value="371"/>
    685       </Item2>
    686       <Item3>
    687         <Source Value="../UMicroThreading.pas"/>
    688         <Line Value="471"/>
    689       </Item3>
    690       <Item4>
    691         <Source Value="../UMicroThreading.pas"/>
    692         <Line Value="288"/>
    693       </Item4>
    694     </BreakPoints>
    695686    <Watches Count="2">
    696687      <Item1>
  • MicroThreading/Demo/UMainForm.pas

    r152 r153  
    6666  private
    6767    procedure Worker(MicroThread: TMicroThread);
     68    procedure WorkerDoWrite;
    6869  public
    6970    Iterations: Integer;
     
    282283      Q := 0;
    283284      while Q < 100 do Inc(Q);
     285      Synchronize(WorkerDoWrite);
    284286      //Memo1.Lines.Add(IntToStr(Id) + ': ' + IntToStr(I) + ' ' +
    285287      //  FloatToStr(ExecutionTime));
     
    291293end;
    292294
     295procedure TMainForm.WorkerDoWrite;
     296begin
     297  Memo1.Lines.Add('.');
     298end;
     299
    293300end.
    294301
  • MicroThreading/MicroThreading.lpk

    r149 r153  
    1717    <License Value="GNU/GPL"/>
    1818    <Version Minor="1"/>
    19     <Files Count="3">
     19    <Files Count="4">
    2020      <Item1>
    2121        <Filename Value="UMicroThreading.pas"/>
     
    3030        <UnitName Value="UPlatform"/>
    3131      </Item3>
     32      <Item4>
     33        <Filename Value="ReadMe.txt"/>
     34        <Type Value="Binary"/>
     35      </Item4>
    3236    </Files>
    3337    <Type Value="RunAndDesignTime"/>
  • MicroThreading/UMicroThreading.pas

    r152 r153  
    6969    procedure Resume;
    7070    procedure Suspend;
     71    procedure Synchronize(AMethod: TThreadMethod);
    7172
    7273    constructor Create(CreateSuspended: Boolean;
     
    118119    FCurrentMicroThread: TMicroThread;
    119120    FScheduler: TMicroThreadScheduler;
     121    FThread: TMicroThreadThread;
    120122    function Execute(Count: Integer): Integer;
    121123  public
    122124    Id: Integer;
    123125    procedure Yield;
     126    procedure Synchronize(AMethod: TThreadMethod);
    124127    constructor Create;
    125128    destructor Destroy; override;
     
    332335end;
    333336
     337procedure TMicroThreadManager.Synchronize(AMethod: TThreadMethod);
     338begin
     339  if Assigned(FThread) then
     340    FThread.Synchronize(FThread, AMethod);
     341end;
     342
    334343constructor TMicroThreadManager.Create;
    335344begin
    336345  FCurrentMicroThread := nil;
     346  FThread := nil;
    337347end;
    338348
     
    487497  FSuspended := True;
    488498  //Yield;
     499end;
     500
     501procedure TMicroThread.Synchronize(AMethod: TThreadMethod);
     502begin
     503  FManager.Synchronize(AMethod);
    489504end;
    490505
     
    538553  FMainThreadManager.Free;
    539554  FThreadPool.Free;
     555  FThreadPoolLock.Free;
    540556  FMicroThreads.Free;
    541557  FMicroThreadsLock.Free;
     
    548564  UpdateThreadPoolSize;
    549565  FState := ssRunning;
     566  if FUseMainThread then
     567    FMainThreadStarter.Enabled := True;
    550568end;
    551569
     
    599617        NewThread := TMicroThreadThread.Create(True);
    600618        NewThread.Manager.FScheduler := Self;
    601         NewThread.Manager.Id := FThreadPool.Count;
     619        NewThread.Manager.Id := FThreadPool.Count + 1;
     620        NewThread.Manager.FThread := NewThread;
    602621        NewThread.OnTerminate := PoolThreadTerminated;
    603622        ThreadPool.Add(NewThread);
Note: See TracChangeset for help on using the changeset viewer.