[fpc-pascal] TThread.FreeOnTerminate

Michael Van Canneyt michael at freepascal.org
Fri Dec 14 11:24:43 CET 2018



On Fri, 14 Dec 2018, OBones wrote:

> Michael Van Canneyt wrote:
>>>> I think FreeOnTerminate should not even exist. IMO it should simply 
>>>> be 'True'.
>>> This is where I strongly disagree, to me it should always be False, 
>>> because having things free up themselves at unpredictable times is a 
>>> recipe for disaster which already hit me badly.
>>> For instance, if a thread is still running when a DLL unloads, you 
>>> get deadlocks. Of if a thread finishes after the memory manager has 
>>> been unloaded, you are in for a hellish shutdown.
>>
>> The opposite problem is just as bad: you cannot guarantee that you can 
>> shut
>> down a thread properly, because you have no idea of the state it is on.
> This is why all my threads are written to be "stoppable". This requires 
> a bit of thinking when writing them, but it's not that hard.
>
>>> All this leads me to believe that FreeOnTerminate should always be 
>>> left to False, even if I can understand it's usefulness in some very 
>>> specific cases.
>>
>> And now we have come to the root of the problem:
>>
>> Threads are unpredictable, and hence evil in programming :-)
>
> Like all powerful tools, if you use them without knowing them, they can 
> hurt you badly.
> But I would not prevent anyone from using a pillar drill just because I 
> once cut through my finger because I was careless when using it...

Agreed, but the manufacturer can maybe be persuaded to make a more safe drill.

Michael.



More information about the fpc-pascal mailing list