[fpc-pascal] TThread.Queue vs TThread.Synchronize
Michael Schnell
mschnell at lumino.de
Mon Feb 23 11:52:00 CET 2015
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
More information about the fpc-pascal
mailing list