[Lazarus] thread safe

Hans-Peter Diettrich DrDiettrich1 at aol.com
Thu Jun 23 07:50:14 CEST 2011


Malcom Haak schrieb:
> Correct me if I'm wrong, But can't you technically make any code 
> 'thread-safe'  by using Critical Sections before doing work. 
> In some code I have seen before a critical section was entered before 
> calling TList.Add

IMO this won't help, because any other thread that does *not* use the 
critical section still can trash the list.

It might help when TList.Add would use a critical section internally, 
but then *all* lists are blocked at once, unless a critical section is 
connected to *every* single TList instance - what may run into 
out-of-resources. Otherwise a global TList.Add lock may lock up an 
entire application, when an OnAdd handler tries to use another 
(temporary...) TList.

IMO. I may be wrong here, because I used threads only on realtime 
systems, never in Delphi or Lazarus...


BTW, I just got my copy of RAD Studio XE, where e.g. thread.suspend is 
deprecated, and other means for thread synchronization are added. But 
these have to be implemented in FPC first, before SpinLock or other 
procedures or methods can be used.

DoDi





More information about the Lazarus mailing list