[Lazarus] Weird object variables access - fpc issue?

el es el.es.cr at gmail.com
Tue Oct 24 10:48:56 CEST 2017


On 24/10/17 09:11, 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:
> 
>> [...]
>> begin
>>   repeat
>>   until not ThreadNowInUse;  // 
>>   
>>   try
>>     ThreadNowInUse :=true;
> 
> This is not thread safe.
> 
> Mattias
> 

Because separated by 'try' ?

I see; Will it be enough to put it like

try
  repeat
  until not ThreadNowInUse;
  ThreadNowInUse := true;

...
 
?

I haven't ran into problems with my routine yet,
but I wasn't really calling it in a very 'tight loop' 

(as it is used for timing/'profiling' the calls to hardware 'master node' routines
 and for deciding whether the thread should go to sleep; so there is always ample time
 between calls to ThreadNow() and it's only called in context of the thread; so the 
 'poor mans semaphore' isn't really that required - it's just a safeguard)

(probably if I need timing measurements, every other type of thread I 
will ever define, will have their own ThreadNow call)

I realize I could just use 'naked' GetSystemTime + SystemTimeToDateTime pair with a local variable;
or define the above pair as a nested function in the thread, that'll serialize it enough...

Anyone ever thought of a thread-safe global Now() call ?

el es



More information about the Lazarus mailing list