[fpc-devel] Suspicion about TThread.Synchronize
Luca Olivetti
luca at ventoso.org
Thu Feb 7 16:17:06 CET 2019
El 7/2/19 a les 0:10, Martin Frb ha escrit:
> On 06/02/2019 23:38, Luca Olivetti wrote:
>>
>> and the exception logged (though the logging in turn uses synchronize).
>
> What OS?
>
> On Windows you can use LazLogger. (in Laz 2.0.0)
> It uses TThread.Queue by default, but you can replace
> TLazLoggerFileHandleMainThread with TLazLoggerFileHandleThreadSave
> in
>
> function TLazLoggerFile.GetFileHandle: TLazLoggerFileHandle;
> begin
> if FFileHandle = nil then
> FFileHandle := TLazLoggerFileHandleMainThread.Create;
> Result := FFileHandle;
> end;
>
> That means that writeln is called in the same thread. (works (at least)
> on windows, but make sure the handle is opened by the main thread, or it
> will be closed by whatever thread did open it, when that thread exits).
Thank you, but by "logged" I mean it is shown on a memo (actually a
TSynEdit because it has much better performance under windows) in the
main form.
i.e.:
procedure TRF182C.DoLog(category: TLogCategory; const msg: string);
begin
FLogStep:=1;
FLogCategory:=category;
FLogMsg:=msg;
FLogStep:=2;
synchronize(@SyncLog);
FLogStep:=1000;
end;
procedure TRF182C.SyncLog;
begin
FLogStep:=3;
FLogProc(self,FLogCategory,CLogCategoryName[FLogCategory]+' RF182C
'+FLogMsg);
FLogStep:=4;
end;
Note the "FLogStep" added to see where the thread stopped. It always
stops with FLogStep 2.
FLogProc is assigned in Create and it's a method of the main form that
adds the message to a TSynEdit (a different one depending on the sender
thread) and logs it to a file.
The thread is created when the application starts and it's terminated
when it's closed (normally never).
Bye
--
Luca
More information about the fpc-devel
mailing list