El 11/12/17 a les 16:14, Michael Van Canneyt ha escrit:
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 :)
Not really: OnTerminate is called in the context of the main thread, so
FThreadId is different than GetCurrentThreadId.
Bye
--
Luca Olivetti
Wetron Automation Technology http://www.wetron.es/
Tel. +34 93 5883004 (Ext.3010) Fax +34 93 5883007
--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus