You are not logged in.
Hello Arnaud,
In a TThread object (TMainThread) I have a TSynLog object (not class):
TMainThread = class
  FLogObj: TSynLog;
  ...
end;And when this TMainThread object is executed, it'll spawn 'sub-threads'.
My question is, is it considered to be safe if those 'sub-threads' also using the FLogObj object of their 'parent-threads'? For example:
  //We use OmniThreadLibrary in this example
  Parallel.ParallelTask.NumTasks(aTaskCount);
  myTasks.Execute(
    //The following anonymous method will be executed in sub-threads and will have multiple instances determined by the aTaskCount param.
    procedure (const task: IOmniTask)
    begin
      //note: here FLogObj is a field of the parent thread.
      FLogObj.Log(sllInfo, 'testing');
    end
  )I read that TSynLog is thread-safe, but I'm not sure if the way I use is thread-safe or not, I appreciate your help!
Edit 1: Some basic tests shows that the above code runs OK without any access violation errors, but I have not done massive (stress) tests.
Last edited by edwinsn (2014-06-09 08:21:09)
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
Thanks for the clarification, ab!
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline