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@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 -- _______________________________________________ Lazarus mailing list Lazarus@lists.lazarus-ide.org https://lists.lazarus-ide.org/listinfo/lazarus