[fpc-devel] question about thread.WaitFor

Martin fpc at mfriebe.de
Sun Nov 11 18:32:09 CET 2018

On 11/11/2018 18:21, Marco van de Voort wrote:
> Op 2018-11-11 om 17:58 schreef Martin:
>> assuming code like this.
>>   SomeThread.Terminate;
>>   SomeThread.WaitFor;
>> and assuming that SomeThread has at some time before that done
>>   Thread.Queue(..., SomeHandler)
>> And the queued item had not run yet.
>> Is WaitFor guaranteed (or supposed) do have the queued message handled?
> Waitfor wait for thread end. If this is needed to be waited for too, 
> the logical place would be in whatever
> calls .execute.
Agreed, just wanted to check.

> Moreover, variables/fields are only destroyed with .free, not with 
> thread termination, so why does it matter?

If SomeHandler is the method of an object that is about to be destroyed, 
then it must be ensured, that it will not be called after (or it will 
access the freed object).
I encountered some code, that called only WaitFor. And, as you 
confirmed, this is not enough. The message is still on the queue, and 
when SomeHandler is called eventually it behaves badly.

More information about the fpc-devel mailing list