On 08 Oct 2010, at 16:13, Andrew Brunner wrote:

I disagree.  I've never had problems with setting values inside
boolean arrays in multi-threaded environments.  The memory is already
allocated.  Setting the value does not cause memory re-allocation,
which would be the only source of problems.

No, the main source of problems is that the cpu may reordering memory operations resulting in those booleans in the arrays becoming true before all memory locations written in the thread are visible. The result is that you may try to use data that the thread should have written earlier, but that in fact is not yet available even though the boolean is already true.

In fact, using atomic operations won't help to solve that problem, you do need memory barriers to flush the memory writes (most pthread functions and ending a pthread guarantee memory barrier behaviour, which is why WaitFor() itself is safe).

On x86 you're unlikely to encounter many problems because of the strongly consistent memory model, but at least x86-64 now also has read and write barrier instructions. On non-x86 architectures, you definitely need memory barriers in such cases.


Jonas
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to