[Lazarus] Lazarus Release 1.8

Michael Van Canneyt michael at freepascal.org
Mon Dec 11 16:14:44 CET 2017



On Mon, 11 Dec 2017, Luca Olivetti wrote:

> El 11/12/17 a les 13:43, Michael Van Canneyt ha escrit:
>
>>> 
>>> [*] I don't know if freeing a thread in OnTerminate is allowed. FPC 
>>> documentation here 
>>> https://www.freepascal.org/docs-html/rtl/classes/tthread.onterminate.html 
>>> says nothing about it, but
>>> the example here (mentioned in the bug report) 
>>> http://docwiki.embarcadero.com/CodeExamples/Tokyo/en/TThreadYield_(Delphi) 
>>> seems to imply that it should.
>> 
>> It is definitely not allowed in FPC, and I will document it as such.
>
> Ouch, that's not delphi compatible then (unless the example is flawed).
> In any case it's better to be not compatible and clearly documented than 
> vaguely documented and maybe (just maybe) compatible (i.e. I don't really 
> care about delphi compatibility since I don't use it, but sometimes you have 
> to rely on delphi examples/documentation).

The following is clearly nonsense:

  FThread.FreeOnTerminate := False;  // Free FThread in the OnTerminate proc. This will set Terminated to true

Terminated is already True in OnTerminate.

So I think the example is flawed.

>From the TThread implementation:

  if (FThreadID = GetCurrentThreadID) then
     begin
       if not(FFreeOnTerminate) and not FFinished then
         raise EThreadDestroyCalled.Create('A thread cannot destroy itself except by setting FreeOnTerminate and leaving!');

I think we cannot be more clear than that :)

Michael.


More information about the Lazarus mailing list