[fpc-devel] threadlocalvar unLOCKed variables

Jonas Maebe jonas.maebe at elis.ugent.be
Sat Jan 9 12:42:03 CET 2010

On 09 Jan 2010, at 11:12, A. Bouchez wrote:

> 1. How does it work on multi-thread? E.g. if you allocate a memory block in a thread, and that TWO threads call Reallocmem() at the same time?

In the past that would have worked if both threads tried to reallocmem it to the same size (otherwise, depending on who got scheduled first, the final size could be too small), so there was only a synchronisation race. Now the result is probably unpredictable in all cases, so there is a data race.

I think in both cases the error is in the program though: you are using a pointer in two threads at the same time, with at least one thread modifying it. Even if both individual operations are atomic respective to each other (like with the old memory manager), depending on the order in which they execute you can still get different results.


More information about the fpc-devel mailing list