Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-09

CRelocateThreadVar called from fpc_pushexceptaddr/fpc_popaddrstack

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Seth Grover

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? 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.

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? If not, can someone explain the reasoning behind this to me?

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

Thanks,

Seth

This email is fiction. Any resemblance to actual events or persons living or dead is purely coincidental. Seth Grover sethdgrover[at]gmail[dot]com

Reply by email

Jonas Maebe
to Seth Grover
Seth Grover wrote 6 lines
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.

Show quoted text 8 lines
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

Reply by email

Seth Grover

Thanks, Jonas. As always your answers are very helpful.

Cheers,

-SG

This email is fiction. Any resemblance to actual events or persons living or dead is purely coincidental. Seth Grover sethdgrover[at]gmail[dot]com

Reply by email