[fpc-devel] threadvar implementation

Michael Schnell mschnell at lumino.de
Tue Jul 27 15:49:15 CEST 2010


  Ranting on....

I did a small testing program using FPC on X86/32 Linux and found that 
GS stays the same with multiple threads (always $0033). So seemingly - 
just like with Windows (Linux using GS instead of FS) - it's not (as I 
supposed) that the GS value is a per-Thread constant, but the selector 
value is constant and the table it points to is different for each thread.

The address of the threadvar is the same in all threads, seemingly the 
address calculation does not acknowledge the threadvar type by modifying 
it's address to make relative to the DS selector (maybe this is not even 
possible at all). Don't use pointers to threadvars !!!! (Maybe this 
caused the problem mentioned in the other thread ???)

In Delphi (Win32) the address of the threadvar is different for the 
threads, as there is one more indirection in Windows, and the the 
FS-depending thread-specific area yields the DS-depending address of the 
final threadvar area.

-Michael



More information about the fpc-devel mailing list