[fpc-devel] Re: TThread.WaitFor delay

Ludo Brands ludo.brands at free.fr
Wed Jun 19 17:34:24 CEST 2013


On 06/19/2013 04:45 PM, Henry Vermaak wrote:
> On Wed, Jun 19, 2013 at 04:05:19PM +0200, Ludo Brands wrote:
>> WaitForThreadTerminate(FHandle, 0) blocks the main thread and skipping
>> the spin on FFinished would block all threads that call synchronize
>> until the thread that is waited for finishes. You can only test
>> assignment of FOnTerminate for the current thread and not for other
>> threads.
> 
> Ah, right.  I thought the spin on FFinished was only needed to prevent
> deadlock if the current thread has an OnTerminate event.  Why worry
> about other threads synchronising at that point?
> 
WaitFor could be called a long time before the thread is finished. If
the mainthread enters WaitForThreadTerminate it won't handle any
synchronize or queued methodes any more. Somebody has to call
CheckSynchronize regularly. So the FFinished loop ends only when the
thread is already done and WaitForThreadTerminate will return quickly.

Ludo



More information about the fpc-devel mailing list