• Advertisement
Sign in to follow this  

What is the function _threadhandle?

This topic is 3233 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am profiling my application with VTune, and this function _threadhandle of MSVCR90.dll is sampled 40% of the time. However, I can't seem to find this function anywhere on the web, except for its declaration in mtdll.h, which is defined to be __threadhandle(). I can't find much information on that either. I'm guessing it is the handle to the current thread (der). So why is it using 40% of my CPU time?

Share this post


Link to post
Share on other sites
Advertisement
This doc from the Wine project says it forwards to GetCurrentThread in Kernel 32. A disassembly of GetCurrentThread shows that it simply returns -2 (0xFE)


; *** GetCurrentThread (272) ***
0x7C57B5AF: 6AFE PUSH 0xFE
0x7C57B5B1: 58 POP EAX
0x7C57B5B2: C3 RET


Another way of looking at this is that every thread recognizes itself as having the handle 0xFE. This is probably an offset into a table of thread handles maintained by the operating system (probably as a priority queue), such that when a thread is executing (and thus able to call GetCurrentThread and/or use the 0xFE handle), it occupies the slot indicated by the 0xFE offset.

At any rate, since this never changes, I don't know why the code in MSVCR90.dll calls it so much. I doubt there's much you can do about it, so focus on optimizing a different portion of your code.

Share this post


Link to post
Share on other sites
_threadhandle isn't called at all in msvcr90.dll, it's not imported by either of the other two CRT dlls and a grep of the CRT source gives no hits apart from the definition.

The function after it in msvcrt90 is the multithreaded initialization of the CRT which initializes numerous critical sections and allocates a couple of chunks of memory. This function isn't exported like _threadhandle is so my guess would be that VTune has defaulted to export symbols and attributed CRT startup cost to by mistake. 40% is still high though unless your app exits quickly.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement