[Lazarus] thread safe
Andrew Brunner
andrew.t.brunner at gmail.com
Tue Jun 28 00:31:21 CEST 2011
On Mon, Jun 27, 2011 at 2:51 PM, Hans-Peter Diettrich
<DrDiettrich1 at aol.com> wrote:
>> Absolutely incorrect.
>
> Why?
>
Two reasons.
1.) Visibility. A critical section does not particularly protect
visibility as with 2 threads accessing a piece of memory.
2.) Execution Order. A critical section does not protect or ensure
that code will be executed in any particular order. This is where
multi-core/multi-threaded systems vs theory get extremely complicated.
AMD vs Intel. Kernels Linux vs Windows. The only way to make sure
you can get code in proper order with regard to memory assignments (
specifically variables) is to use Interlocked methods. This is why
they were designed.
The analogy would be like using a wisk vs a commerical grade mixer to
scramble your eggs. Use the commercial grade mixer in this case
(CriticalSection) and expect a high cost of use and tons of wait
states - which translates into poor benchmarks.
More information about the Lazarus
mailing list