[fpc-devel] threadvar implementation
jonas.maebe at elis.ugent.be
Fri Aug 6 11:29:08 CEST 2010
On 06 Aug 2010, at 09:51, Michael Schnell wrote:
> On 08/06/2010 12:31 AM, Jonas Maebe wrote:
>> (but keep in mind that the only reason that intialising/finalising
>> threads not started via the FPC rtl now works under Unix is exactly
>> because every threadvar access requires a call into a helper
> Of course this is why I started the thread.
I said that the (recently introduced) support for externally started
threads under Unix *depends* on the fact that you cannot access a
threadvar without calling that helper routine at least once. You did
not start the thread with the purpose of breaking that support again,
but as I said such breakage would be a direct consequence of moving to
direct selector-based accesses on Unix platforms.
> The C compilers seem to work more efficient on that behalf and thus
> it might be viable to improve FPC.
If you really need fast access to a thread variable, take its address
and use that afterwards. That's what e.g. the heap manager does. In
general, I doubt that the speed of accessing threavars matters much to
Nevertheless, if you want to add support for accessing threadvars
under Windows via a segment override, feel free to debug it. The basic
code is already in the compiler from previous (failed) experiments.
Uncomment tf_section_threadvars in compiler/systems/i_win.pas, and
grep for its occurrences in the compiler source code to see what it
> To do that the details of how segment registers are used with the
> X86/32 architecture in Linux and Windows needs to be thoroughly
This thread has gone on long enough about that subject, and most of
the details that have been discussed are completely irrelevant
regarding anything FPC would have to do when using them to access
threadvars. If you feel that anything further needs discussing about
that, then do it on a list specific to low level programming on Linux,
Windows or for the x86 architecture (or on fpc-other).
> (In fact I still don't know how the compiler should construct a
> pointer to a threadvar in Linux).
It (indirectly) calls CRelocateThreadvar() in rtl/unix/cthreads.pp
More information about the fpc-devel