[Lazarus] Weird object variables access - fpc issue?
el es
el.es.cr at gmail.com
Tue Oct 24 13:41:11 CEST 2017
On 24/10/17 10:04, Mattias Gaertner via Lazarus wrote:
> On Tue, 24 Oct 2017 08:59:36 +0100
> el es via Lazarus <lazarus at lists.lazarus-ide.org> wrote:
>
>> 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;
>
> AFAIK Now is thread safe. On what platform and how did you test?
>
> Mattias
>
Now() is literally
function Now : TDateTime;
var ASystemTime : TSYSTEMTIME;
begin
GetSystemTime(ASystemTime);
Result := SystemTimeToDateTime(ASystemTime);
end;
on my installation (lazarus 1.6.4 #54278, FPC 3.0.2)
I'd say it's questionable to say it's thread-safe that way; It may be safe to use in
main thread (where no 2 different contexts can mangle each others ASystemTime);
But I had problems using Now() in main thread context (graphic) and in additional thread(s)
_simultaneously_.
I do not recall getting AV's, but I was getting mangled results when calls to Now() overlapped from 2 different thread contexts.
(try it by calling Now() from a TTimer.OnTimer handler, simultaneously with a background thread also calling Now() in a loop.)
I guess, simpler code for ThreadNow would be 'just' thread-local/nested to Execute() function containing just
a pair of
GetSystemTime(ASystemTime);
Result := SystemTimeToDateTime(ASystemTime);
(or literally a copy of Now(); )
because each thread instance would have its own local variables, right?
so no thread would step on each others' toes;
Hopefully this makes sense now ;)
el es
More information about the Lazarus
mailing list