[Lazarus] TThread.WaitFor blocks the main event loop under Linux

Sven Barth pascaldragon at googlemail.com
Fri Oct 8 20:18:12 CEST 2010


On 08.10.2010 18:40, Luca Olivetti wrote:
> Al 08/10/10 15:17, En/na Graeme Geldenhuys ha escrit:
>
>>
>> If you use the MyThread.WaitFor to wait for the thread to finish, then
>> the application is instantly frozen (even the thread), nothing gets
>> updated and you have to kill the process. For some reason
>> WaitFor blocks the main thread's event loop. It seems this issue is
>> only under FPC apps and under X11 (no matter the GUI toolkit),
>> it works fine under Windows.
>
> I'm surprised it works under windows: using synchronize and waitfor has
> always been a no-no.
>
> Bye

No need to be surprised.

Windows RTL uses MsgWaitForMultipleObjects to wait on the thread's 
handle and the handle of the Synchronize event (that event is set if a 
thread calls Synchronize). If the Synchronize event becomes signaled it 
calls CheckSynchronize (thus no deadlock in this scenario) and continues 
waiting. Also the use of MSGWaitFor* allows that window messages are 
still processed allow the (main) thread is waiting.

Regards,
Sven




More information about the Lazarus mailing list