<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 09 Sep 2010, at 20:38, Seth Grover wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Monaco; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">The documentation<br>(<a href="http://www.freepascal.org/docs-html/prog/progse46.html">http://www.freepascal.org/docs-html/prog/progse46.html</a>) indicates<br>that "RelocateThreadVar is called each time when a thread is started,<br>and once for the main thread."<br><br>Is it not called much more frequently than this?</span></blockquote><div><br></div><div>Yes.</div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Monaco; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">I was doing some<br>profiling with valgrind and noticed that every call to<br>fpc_pushexceptaddr/fpc_popaddrstack resulted in a call to<br>CRelocateThreadVar. From stepping through in gdb, it appears that<br>*every* time a threadvar is accessed (in this case, the exception<br>stack). It doesn't run through all of the code of CRelocateThreadVar<br>because of the non-nill result of pthread_getspecific, but it is<br>called.<br></span></blockquote><div><br></div><div>That's correct.</div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Monaco; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">It seems that every time a threadvar is accessed, we're checking to<br>make sure threadvars have been initialized/allocated for this<br>particular thread. Is that correct?</span></blockquote><div><br></div><div>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).</div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Monaco; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">I can certainly see why exceptions are to be avoided in<br>performance-critical code. :).<br></span></blockquote></div><br><div>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.</div><div><br></div><div><br></div><div>Jonas</div></body></html>