[fpc-pascal] CRelocateThreadVar called from fpc_pushexceptaddr/fpc_popaddrstack

Jonas Maebe jonas.maebe at elis.ugent.be
Thu Sep 9 20:49:56 CEST 2010


On 09 Sep 2010, at 20:38, Seth Grover wrote:

> The documentation
> (http://www.freepascal.org/docs-html/prog/progse46.html) indicates
> that "RelocateThreadVar is called each time when a thread is started,
> and once for the main thread."
> 
> Is it not called much more frequently than this?

Yes.

> I was doing some
> profiling with valgrind and noticed that every call to
> fpc_pushexceptaddr/fpc_popaddrstack resulted in a call to
> CRelocateThreadVar. From stepping through in gdb, it appears that
> *every* time a threadvar is accessed (in this case, the exception
> stack). It doesn't run through all of the code of CRelocateThreadVar
> because of the non-nill result of pthread_getspecific, but it is
> called.

That's correct.

> It seems that every time a threadvar is accessed, we're checking to
> make sure threadvars have been initialized/allocated for this
> particular thread. Is that correct?

Yes, to support threads that are started in external code. Note that the check is basically for free, since we have to call pthread_getspecific() anyway to get the content of the regvar (unless someone implements and maintains, for those architectures and platforms that have a supported API to do so, direct threadvar access support).

> I can certainly see why exceptions are to be avoided in
> performance-critical code. :).

The threadvar accesses are unlikely to impact the speed of exception handling much if anything. The setjmp and memory allocation/freeing are way more expensive.


Jonas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freepascal.org/lists/fpc-pascal/attachments/20100909/7477c4ab/attachment.htm


More information about the fpc-pascal mailing list