Vincent Snijders wrote:
Giuliano Colla schreef:
Martin Schreiber ha scritto:
On Sunday 30 December 2007 07.39:25 Micha Nelissen wrote:
Martin Schreiber wrote:
You are right, there seems to be no race condition if one uses
WakeMainThread correct. There can be a deadlock if the main thread
tries
to destroy a thread which is waiting for Synchronize.
Hmm I think this is a very stupid idea to do. The thread will continue
to execute something so I don't think this is supported. Like
destroying
a component in an event handler.
TThread.Destroy calls Waitfor.
What is the supported method to terminate an application which has
threads waiting for Synchronize?
I don't know it it's officially supported, but for me it works.
I've added a Running property to my thread, which is set true when the
thread begins execution, and false jut before terminating.
In my main form, the OnClose event includes:
if assigned(Thr1) then begin
if Thr1.Running then begin
Thr1.Terminate;
Thr1.WaitFor;
end;
end;
Isn't that where the dead lock occurs? Suppose Thr1 has just called
Synchronize and is waiting until the main thread has executed the
synchronized method, it won't terminate, because you have suppended the
main thread by waiting for Thr1 to terminate.
IIRC WaitFor also handles the main loop (at leasst on delphi)
Marc
_________________________________________________________________
To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives