[Lazarus] thread safe
Michael Schnell
mschnell at lumino.de
Mon Jun 27 15:49:18 CEST 2011
On 06/27/2011 03:31 PM, Andrew Brunner wrote:
> Simply protecting a loop with a futex is not sufficient. Assigning
> variables in a multi-threaded environment is not sufficient.
While I don't think we should this discuss in this context, I suggest
that in the docs for the user of the object library (that was the
starting point of the discussion), any type of thread-safety should
include threads running on multiple processors.
> Interlocked/Exchange/ExchangeAdd/Increment features must be used
> whenever dealing with variables (with at least one exception) In my
> experience arrays of boolean are atomic.
Yep. But this is only relevant if you don't protect them by a critical
section, as this excludes concurrent exchange before the critical
instructions are executed. Of course (when possible) using the
interlocked instruction results in a lot less overhead than simply using
a critical section.
> I ran tests on a HexCore AMD system which had unexplained anomalies
> with pointers in an bidirectional linked list. I replaced all the
> pointer assignments with InterlockedExchange and the system worked
> flawlessly.
This is clear. You also would have been able to avoid the problem by
using critical sections around *all *the appropriate instructions, but
supposedly this would have slowed done the application greatly.
> Some of the assignments were taking place in a
> criticalsection (btw).
I believe that the "some" were not enough.
-Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20110627/85c9b340/attachment-0003.html>
More information about the Lazarus
mailing list