Thema: Delphi Threads

Einzelnen Beitrag anzeigen

shmia

Registriert seit: 2. Mär 2004
5.508 Beiträge
 
Delphi 5 Professional
 
#7

Re: Threads

  Alt 17. Nov 2004, 15:32
Delphi-Quellcode:
procedure TPiCalc.Execute;
var x, y:Extended;
    PointsIn, PointsAll:Int64;
begin
  randomize;
  PointsIn := 0; // <==== !!!!!!!!!!!!!
  PointsAll:= 0; // <==== !!!!!!!!!!!!!
  while not Terminated do
    begin
    x:=random;
    y:=random;
    if sqr(x)+sqr(y)<1.0 then inc(PointsIn);
    inc(PointsAll);

    // wenn nach jeder Berechnung sofort eine Ausgabe erfolgen würde
    // braucht man keine Threads !!
    if (PointsAll mod 1000) = 0 then
    begin
       Value:=4.0*PointsIn/PointsAll;
       Synchronize(Ausgabe);
    end;
  end;
  Value:=4.0*PointsIn/PointsAll;
end;
Andreas
  Mit Zitat antworten Zitat