[fpc-pascal] Context of TThread.OnTerminate

Mattias Gaertner nc-gaertnma at netcologne.de
Thu Feb 24 16:48:21 CET 2011


On Thu, 24 Feb 2011 15:36:17 +0200
Wimpie Nortje <wimpienortje at gmail.com> wrote:

> Hi everybody,
> 
> The manual (possibly Delphi one) says that TThread.OnTerminate executes
> in the GUI thread. This is easy if the GUI thread owns the TThread.
> 
> Suppose the GUI owns a TTHread which owns a subthread. In which context
> does the subthread's OnTerminate execute?

Under unix OnTerminate is always called in the main thread:

procedure TThread.CallOnTerminate;
begin
  // no need to check if FOnTerminate <> nil, because
  // thats already done in DoTerminate
  FOnTerminate(self);
end;

procedure TThread.DoTerminate;
begin
  if Assigned(FOnTerminate) then
    Synchronize(@CallOnTerminate);
end;


Mattias



More information about the fpc-pascal mailing list