[Lazarus] thread safe

Mark Morgan Lloyd markMLl.lazarus at telemetry.co.uk
Tue Jun 28 14:37:10 CEST 2011


Henry Vermaak wrote:
> On 27/06/11 23:31, Andrew Brunner wrote:
>>
>> 2.) Execution Order.  A critical section does not protect or ensure
>> that code will be executed in any particular order.  This is where
> 
> How do you know this?  Unfortunately I can't read the code for the 
> Windows critical sections and the documentation doesn't explicitly state 
> anything, but at least pthread mutex guarantees a memory barrier.  So if 
> you're using the fpc rtl critical sections on unix (which uses 
> pthread_mutex), your statement is false.
> 
> You'll have to read the generated assembler for Windows critical 
> sections.  My hunch would be that they use memory barriers, too.

On processors that support them, which I think excludes x86.

My understanding is that in the general case membars are there to 
enforce sanity when a processor can reorder memory accesses. As such 
they don't guarantee anything either way when multiple threads are 
considered on an SMP/multicore system, they're just part of the overall 
picture.

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]




More information about the Lazarus mailing list