Ignore:
Timestamp:
Jan 27, 2011, 8:05:33 AM (14 years ago)
Author:
george
Message:
  • Modified: Elimination of global variables used by TMicroThreadManager Yield method.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • MicroThreading/Demo/UMainForm.pas

    r150 r151  
    2626    Label10: TLabel;
    2727    Label11: TLabel;
     28    Label12: TLabel;
    2829    Label2: TLabel;
    2930    Label3: TLabel;
     
    3940    SpinEdit1: TSpinEdit;
    4041    SpinEdit2: TSpinEdit;
     42    SpinEdit3: TSpinEdit;
    4143    TabSheet1: TTabSheet;
    4244    TabSheet2: TTabSheet;
     
    5759    procedure ListView1Data(Sender: TObject; Item: TListItem);
    5860    procedure SpinEdit2Change(Sender: TObject);
     61    procedure SpinEdit3Change(Sender: TObject);
    5962    procedure TimerRedrawTimer(Sender: TObject);
    6063    procedure TimerSchedulerStartTimer(Sender: TObject);
     
    6265    procedure Worker(MicroThread: TMicroThread);
    6366  public
     67    Iterations: Integer;
    6468    Scheduler: TMicroThreadScheduler;
    6569  end;
     
    209213procedure TMainForm.FormShow(Sender: TObject);
    210214begin
     215  Iterations := SpinEdit3.Value;
    211216end;
    212217
     
    236241end;
    237242
     243procedure TMainForm.SpinEdit3Change(Sender: TObject);
     244begin
     245  Iterations := SpinEdit3.Value;
     246end;
     247
    238248procedure TMainForm.TimerRedrawTimer(Sender: TObject);
    239249begin
    240   ListView1.Items.Count := Scheduler.MicroThreadCount;
     250  if ListView1.Items.Count <> Scheduler.MicroThreadCount then
     251    ListView1.Items.Count := Scheduler.MicroThreadCount;
    241252  ListView1.Items[-1];
    242253  ListView1.Refresh;
     
    258269  I: Integer;
    259270  Q: Integer;
    260 const
    261   TotalSteps = 100;
    262271begin
    263272  with MicroThread do begin
    264273    //Memo1.Lines.Add('Worker ' + IntToStr(Id));
    265     for I := 0 to TotalSteps - 1 do begin
     274    for I := 0 to Iterations - 1 do begin
    266275      Q := 0;
    267       while Q < 10000 do Inc(Q);
     276      while Q < 100 do Inc(Q);
    268277      //Memo1.Lines.Add(IntToStr(Id) + ': ' + IntToStr(I) + ' ' +
    269278      //  FloatToStr(ExecutionTime));
    270       Completion := I / TotalSteps;
     279      Completion := I / Iterations;
    271280      //Sleep(1 * Id * OneMillisecond);
    272281      Yield;
Note: See TracChangeset for help on using the changeset viewer.