En/na Michael Van Canneyt ha escrit:


and in "WaitFor" it says:

"Call WaitFor to obtain the value of ReturnValue when the
thread finishes executing. WaitFor doesn't return until the thread
terminates, so the thread must exit either by finishing the Execute method
or by exiting when the Terminated property is true."

There you have it. Nowhere does it say that if the main thread is blocked,
your synchronize() method will be executed nonetheless. Indeed, both specs
explicitly say that the calling thread is suspended or blocked (!) till the call returns.


And in older versions of the documentation (delphi 2) it explicitly says

"Don't call WaitFor in the context of the main VCL thread if your thread uses Synchronize. Doing so will either cause a deadlock, making it appear that your application has hung, or cause an EThread exception to be raised. (Synchronize waits for the main VCL thread to enter the message loop before allowing the method it is trying to synchronize to execute. If the main VCL thread has called WaitFor, it won't enter the message loop and Synchronize will never return. TThread detects that case and will raise an EThread exception in the thread, causing it to terminate and, if not caught in the Execute method, the application will terminate as well. If Synchronize is already waiting on the main VCL thread when WaitFor is called, TThread can't intervene, and your application will deadlock.)"

They probably changed the implementation later on to avoid this, but old farts like me still avoid to mix synchronize and waitfor.

Bye
--
Luca Olivetti
Wetron Automatización S.A. http://www.wetron.es/
Tel. +34 93 5883004 (Ext.133)  Fax +34 93 5883007

--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to