On 02/23/2015 11:08 AM, Graeme Geldenhuys wrote:
Hi,

I've recently seen some posts in Delphi groups that the preferred way is
to use TThread.Queue instead of TThread.Synchronize.
TThread.Queue just "fires" an Event in the main thread. This means a "mark" is set that the event handler function is to be started by the main thread. Same performs this "as soon as possible", meaning that it is done as soon as the man thread is idle (no previously scheduled Events ("fired" by threads, GUI, ...) are in the pipe any more.

TThread.Synchronize does exactly the same, only that the thread calling TThread.Synchronize is frozen after firing the event, and the event handler is enhanced by code that frees the thread after the user code of the event handler is finished.

TThread.Queue works very similar to Application.QueueAsyncCall in the LCL


Why is that? What are the benefits?
Obviously TThread.Queue does not hamper the firing thread, while TThread.Synchronize stalls it for an undefined amount of time.
As a benefit TThread,Synchronize avoids imposing mutual access issues,.

-Michael

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to