Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Ist der Thread schuld? (https://www.delphipraxis.net/122356-ist-der-thread-schuld.html)

Neutral General 14. Okt 2008 20:53


Ist der Thread schuld?
 
Hi,

Delphi-Quellcode:
procedure TCellThread.Execute;
begin
  repeat
    Synchronize(DoCalculate);
    Synchronize(FAutomaton.Paint);
    inc(FAutomaton.FGen);
  until Terminated;
end;
Während dieser Thread seine Arbeit verrichtet (Ist jetzt erstmal egal was er genau tut), taucht nach kurzer Zeit folgendes Phänomen auf:

Ich erhalte bei einem einfachen Lesezugriff auf eine Variable eines Objekts eine Zugriffsverletzung:

Zitat:

---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 0044F989 in module 'Project1.exe'. Write of address 00000044'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
Das sieht ganz danch aus, als würde das Objekt nichtmehr existieren, bzw als wäre der Self-Pointer verbogen.

Sowas kann imo durch Threads passieren. Aber ich Synchronisiere doch alles. Warum passiert sowas? (es passiert übrigens auch wenn ich

Delphi-Quellcode:
inc(FAutomaton.FGen);
auskommentiere.

Gruß
Neutral General

Apollonius 14. Okt 2008 20:57

Re: Ist der Thread schuld?
 
Von wo erfolgt dieser Zugriff und wie wird die Objektinstanz erhalten?

Nebenbei bemerkt: Ist dieser Thread nicht ziemlich sinnlos? Da du alles synchronisierst, wird alles im Hauptthread ausgeführt.

Neutral General 14. Okt 2008 21:19

Re: Ist der Thread schuld?
 
Hi,

Alsooo... Der Callstack:

Delphi-Quellcode:
TCellularAutomatonEx.SetWorld(0,2,$26FC63C)
TWatorObject.Move(???)
TWatorSimulation.Calculate
TCustomCellularAutomaton.DoOnCalculate(???)
TCellThread.DoCalculate
TCellThread.Execute
Ich glaube die Zeile ausgemacht zu haben, an der es passiert:

TWatorObject.Move:

Delphi-Quellcode:
// FWorld: Array of Array of Pointer;
FWorld[fy,fx] := Self;
Setter:

Delphi-Quellcode:
procedure TCellularAutomatonEx.SetWorld(y, x: Integer;
  const Value: Pointer);
begin
  FEgal := 24; // <--- AV
  // ...
end;
Ehm... Ja warum ich das in nem Thread mache wenn ich eh alles Synchronisiere... Ehm keine Ahnung :oops:


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:19 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz