Hi,
kaum habe ich ein Problem gelöst, kommt das nächste..
Mein erster Thread läuft soweit nun

.. wenn ich allerdings einen 2. erstelle und starte, so hängt sich das Programm sofort auf und freezt. Sieht also nach einem Deadlock aus, allerdings sehe ich nicht wo dieser erzeugt wird..
Hier mein Quelltext:
Die Thread-Klasse:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48:
| unit Unit2;
interface
uses Classes, sysutils, StdCtrls, SyncObjs;
type TDLThread = class(TThread) private count: integer; GUI: TLabel; protected procedure Execute; override; procedure DoSync; public constructor Create(pGUI: TLabel); end;
implementation
constructor TDLThread.Create(pGUI: TLabel); begin GUI := pGUI; FreeOnTerminate := True; inherited Create(False); Suspend(); end;
procedure TDLThread.Execute; begin while not terminated do begin count := count + 1; Synchronize(DoSync); end; end;
procedure TDLThread.DoSync(); begin GUI.caption := inttostr(count); end;
end. |
Und das Programm:
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29:
| var dlthreads : array of tdlthread;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject); begin dlthreads[0].Resume(); end;
procedure TForm1.Button2Click(Sender: TObject); begin dlthreads[0].Suspend; end;
procedure TForm1.FormCreate(Sender: TObject); begin setlength(dlthreads, 2); dlthreads[0] := tdlthread.Create(label1); dlthreads[1] := tdlthread.Create(label2); end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin dlthreads[0].Terminate(); end; |
Sobald ich den dlthreads[1] mit Resume starte, hängt sich das Programm sofort auf. Kann dann nur noch per STRG+F2 beenden werden.. lasse die Threads alle Suspended starten.
Ich hoffe, Ihr könnt mir helfen

!
Grüße
Passi