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

Sven Barth pascaldragon at googlemail.com
Tue Oct 12 11:03:26 CEST 2010


Am 12.10.2010 10:51, schrieb Michael Schnell:
> On 10/12/2010 10:38 AM, Sven Barth wrote:
>> just calls pthread_join, which waits for the thread to terminate
>> (without a timeout or other gimmicks like on Windows).
>>
> Sound nice and straight forward. In Windows of course this needs to be
> emulated (supposedly using Messages).
>
> So -> OP:
> does it work decently in Linux ?
> does it work decently in Windows ?

Huh? The problem is this (as I've sent on numerous other mails last week):

On Windows WaitFor does not use WaitForThreadTerminate, but uses 
MsgWaitForMultipleObjects on two handles: the thread handle and the 
handle of the event which is set when a thread calls Synchronize.
Now if the thread handle is signaled all is well and the job of 
WaitForThreadTerminate is done.
If the synchronize event is signaled the method calls CheckSynchronize 
(thus all threads waiting on a Synchronize have a satisfied wait now) 
and continues waiting on the thread handle after that.
But MsgWaitForMultipleObjects has another speciality: If a new message 
arrives in Windows' message queue of the waiting thread (normally the 
main thread) this message is handled by calling PeekMessage and thus the 
message pump will keep working!

This is a significient difference to the way WaitFor in cthreads works 
and behaves (this one just blocks and sits there waiting for the thread).

Regards,
Sven




More information about the Lazarus mailing list