[Lazarus] How does one add an event to a blocking system?

Michael Schnell mschnell at lumino.de
Wed Oct 21 14:59:28 CEST 2015


On 10/21/2015 02:42 PM, Michael Schnell wrote:
> CheckSynchronize()
>
Unfortunately there is no decent documentation on CheckSynchronize().

So in very short (and just hopefully correct):

CheckSynchronize() needs to be called by the main thread (in fact a 
threat becomes the main thread _because_ it calls CheckSynchronize().

The Events thrown by other Threads via TThread.Synchronize and 
TThread.Queue are executed as sub-procedures of CheckSynchronize() and 
hence they are executed in the main thread and they are executed in the 
order they have been queued by other threads.

It is a very bad idea to do a closed loop such as

while (TRUE) CheckSynchronize();

As this will use 100 % CPU time and hence will reduce the performance of 
all other threads (and every application that is running on the processor).

That is why CheckSynchronize() provides using the parameter "Timeout", 
that defines how long to wait until returning in case no event is 
queued.  (0 or no parameter => return immediately)

AFAIR if an Event is in the queue same is executed and 
CheckSynchronize(I) returns without checking if more Events are queued.

AFAIK the return parameter of CheckSynchronize() does not give any 
decent result and needs to be ignored.

-Michael




More information about the Lazarus mailing list