[Lazarus] thread safe

Martin lazarus at mfriebe.de
Mon Jun 27 11:37:48 CEST 2011


On 22/06/2011 23:37, Malcom Haak wrote:
> Correct me if I'm wrong, But can't you technically make any code 
> 'thread-safe'  by using Critical Sections before doing work. 

I don't think so.

If the function, for example stores some important data in a thread 
local variable, but flags (thread global) the availability of the data, 
then no Critical section will fix it.

Admittedly this is a constructed case, and sounds like an extremely poor 
implementation... But it shows that thread-safety is more than just a 
Critical Section. After execution of a thread-save function the overall 
state of your app (and the entire system) must still be valid (and it 
must be so, for each thread).

Martin





More information about the Lazarus mailing list