[Lazarus] thread safe

Andrew Brunner andrew.t.brunner at gmail.com
Tue Jun 28 01:41:46 CEST 2011


2011/6/27 Malcom Haak <insanemal at gmail.com>:
> Tell me then why any of what you have said is relevant. In fact in cases
> this this the use of CriticalSections would be sensible and would not cause
> 'tons of wait' as you have all your worker threads off doing things 99% of
> the time.

Thread 1:
a=b+c
a2=a+c2
SignalEvent(E1)

Thread 2:
  repeat
  WaitForEvent(E1,120);
    We can read anything now
  until terminated or complete

This the prime example.  On a 6 core system a looks like one value to
one core than it does to another core.  It's that simple.  No getting
around this issue.

While spinlocks can block a entrance - it cannot guarantee memory
order / code execution order.  Therefore it is good practice to adopt
interlocked assignments to guarantee memory is what it is.


Core X computes a=b+c
Core X+Y computes a2

This is relatively new theory which required low-level CPU code to
perform such locks.  This was never needed until the introduction of
multi-core systems.  Of which I did extensive tests on AMD via
FPC/Lazarus.




More information about the Lazarus mailing list