Forum > Other
TThread collapses application
fatg:
I've made a very very simple TThread descendant, here is the source:
--- Code: ---
TTestThread = class(TThread)
protected
procedure Execute; override;
public
constructor Create;
end;
implementation
constructor TTestThread.Create;
begin
inherited Create(True);
FreeOnTerminate := True;
end;
procedure TTestThread.Execute;
begin
Sleep(1000);
end;
--- End code ---
I am testing it with this code:
--- Code: ---
var
ThreadCount: Integer;
procedure TForm1.ThreadOnTerminate(Sender: TObject);
begin
Dec(ThreadCount);
Label1.Caption := IntToStr(ThreadCount);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ThreadCount := 0;
Label1.Caption := IntToStr(ThreadCount);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
with TTestThread.Create do
begin
Inc(ThreadCount);
Label1.Caption := IntToStr(ThreadCount);
OnTerminate := @ThreadOnTerminate;
Resume;
end;
end;
--- End code ---
This simple example collapses my application every time. Sometimes the second thread destroys it, other times it's seventh. They don't have to run consequently, the application terminates even if I create one thread at a time with waits between them. Clicking very fast produces a lot of threads, although it collapses long before I come to 32 (I can produce 32 threads with fast-clicking in the same application in Delphi6 without problems).
This test was ran in Delphi6 several times. No errors occurred, although I am aware of the danger of accessing ThreadCount variable and Label1 component without locking.
Is this an FCL error, do you think it's a bug or is the error on my side? Does the same thing happen to you?
Best regards,
G
IgD:
Fatq, Delphi 7 comes with a threads demo. It does some visual sorting routines. Have you tried porting it to Lazarus for testing? That would be a great diagnostic tool.
fatg:
Thanks for the suggestion, I've ported D6 Threads demo, here it is:
http://pzs.asit.si/data/threads.rar
exe included
It proves that TThread is very unstable in fpc.
fatg:
Oh, and my nick is fatg, not fatq. Not that it really matters, I've just notices the underline font style completely hides the difference between g and q. And you also have the same problem :)
Anonymous:
Excellent work! I wonder who from the Lazarus team can check this out.
Navigation
[0] Message Index
[#] Next page