[fpc-pascal] Where is IsMultiThreaded set under Linux?

Jonas Maebe jonas.maebe at elis.ugent.be
Fri Oct 8 16:21:22 CEST 2010


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



More information about the fpc-pascal mailing list