[fpc-pascal] TThread.WaitFor not returning?
Graeme Geldenhuys
graemeg.lists at gmail.com
Tue Sep 16 13:07:36 CEST 2008
Hi,
I have a thread based logging framework (part of tiOPF). I created a
"Log to GUI" viewer for the log framework using fpGUI toolkit. While
the application runs, the cached logging to the GUI window works
perfectly - no problems there. For some reason, the call to the
internal TThread.WaitFor doesn't always return when the application
terminates. The viewer is based on code for Delphi's VCL, which never
showed this issue.
I'm not sure how to debug threads and don't have a clue as to what
could cause the problem.
My application is built with FPC 2.2.3 and fpGUI toolkit, running
under Ubuntu Linux 7.10 (2.6 based kernel).
Example of a successful termination:
graemeg at graemeg:tutoradmin$ ./tutoradmin.exe -lv
TtiLogToGUI.FormClose called
>> TfpgApplication.Destroy
destroying components... DONE
killing message queue
<< TfpgApplication.Destroy
>> TtiLogToCacheAbs.Terminate
called .Terminate() and now calling .WaitFor()
<< TtiLogToCacheAbs.Terminate
graemeg at graemeg:tutoradmin$
An example, where the application doesn't terminate.
graemeg at graemeg:tutoradmin$ ./tutoradmin.exe -lv
TtiLogToGUI.FormClose called
>> TfpgApplication.Destroy
destroying components... DONE
killing message queue
<< TfpgApplication.Destroy
>> TtiLogToCacheAbs.Terminate
called .Terminate() and now calling .WaitFor()
I have to press Ctrl+C to terminate the application fully.
TtiLogToCacheAbs is a abstract base class used for cached logging. It
contains a TCriticalSection and a TThread.
TtiLogToGUI is a descendant of TtiLogToCacheAbs and contains the GUI
Form instance (visual logging). The GUI Form is closed and destroyed
before the Application or thread terminates. It's the first output
line (....FormClose) shown above...
Here is the section of code which doesn't complete 100% and hangs the
application when the application gets terminated.
procedure TtiLogToCacheAbs.Terminate;
begin
writeln('>> TtiLogToCacheAbs.Terminate');
FThrdLog.Terminate;
writeln(' called .Terminate() and now calling .WaitFor()');
FThrdLog.WaitFor;
writeln('<< TtiLogToCacheAbs.Terminate');
end;
Any ideas?
Regards,
- Graeme -
_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
More information about the fpc-pascal
mailing list