[Lazarus] Weird object variables access - fpc issue?

el es el.es.cr at gmail.com
Tue Oct 24 09:59:36 CEST 2017


On 23/10/17 20:00, Giuliano Colla via Lazarus wrote:
[snip]

I don't remember if I was hitting AV using Now(), likely I wasn't - 
but due to 'normal' Now() being not thread safe, I was getting inconsistent 
timing results, when I used Now() both in main thread and in the thread;

So with my application I ended up re-implementing Now() into ThreadNow :

var ThreadNowInUse :boolean = false; // unit global 'just' above the function

function TMyThread.ThreadNow: TDateTime;

var ASystemTime : TSYSTEMTIME;  // struct.inc, I'm under Windows

begin
  repeat
  until not ThreadNowInUse;  // 
  
  try
    ThreadNowInUse :=true;
    GetSystemTime(ASystemTime);
    Result := SystemTimeToDateTime(ASystemTime);
  finally
    ThreadNowInUse := false;
  end;

end;

Hope this helps

el es



More information about the Lazarus mailing list