Any Api on win NT to get thread handle from thread id?.

Any Api on win NT to get thread handle from thread id?.

Post by Slava M. U » Sun, 10 Jul 2005 01:22:32



[...]


One problem with that code is that it does not wait for actual thread object
destruction. This is not possible in user mode, anyway. I'm not saying this
is why you observe what you observe, but this might be a factor.

S
 
 
 

Any Api on win NT to get thread handle from thread id?.

Post by Eugene Ger » Sun, 10 Jul 2005 01:43:35


But shouldn't the actual destruction happen before the last CloseHandle
returns?

--
Eugene
http://www.yqcomputer.com/

 
 
 

Any Api on win NT to get thread handle from thread id?.

Post by Skywin » Sun, 10 Jul 2005 01:55:17

Not necessarily, kernel mode components could have a pointer reference to
the thread object. This would cause the thread object to remain even after
the last handle reference was closed.
 
 
 

Any Api on win NT to get thread handle from thread id?.

Post by Slava M. U » Sun, 10 Jul 2005 01:57:24


No, why? A file object may stay referenced by the cache manager for hours
after the last CloseHandle().

S
 
 
 

Any Api on win NT to get thread handle from thread id?.

Post by Eugene Ger » Sun, 10 Jul 2005 02:48:04


I see.

At the end it amounts to the same thing. Whether OS deliberately holds IDs
for some time or just doesn't destroy thread objects right after user mode
finished with them the ID will not be reused for some (possibly small) time.

--
Eugene
http://www.yqcomputer.com/
 
 
 

Any Api on win NT to get thread handle from thread id?.

Post by Skywin » Sun, 10 Jul 2005 03:09:32

You cannot rely on this, however.

A robust application must assume that as soon as the last handle that it
knows about for a process has been closed (and the process has been
terminated), that the process id has been reused and is invalid.
 
 
 

Any Api on win NT to get thread handle from thread id?.

Post by William De » Sun, 10 Jul 2005 06:27:04


Yes, but I use VS.Net 2003. :-)

Seriously, I _think_ that this hokey business of naming threads by raising
an exception was added because managed threads don't expose the native
thread ID to track them easily. With VC6 having been released before .Net
you are limited to what the platform provides - i.e. no name. :-(

Regards,
Will
 
 
 

Any Api on win NT to get thread handle from thread id?.

Post by James Brow » Sun, 10 Jul 2005 16:54:26

I looked back at the VC6 debug->threads window and you're right,
there's no thread name listed, just the name of the location of the current
location -
which I mistook it for.

James

--
www.catch22.net
Free win32 software, sourcecode and tutorials
 
 
 

Any Api on win NT to get thread handle from thread id?.

Post by Christian » Thu, 15 Jun 2006 13:15:23

William,

where can i see the thread name set by that code? WinDBG does not show any
name in the thread/process window...

Christian
 
 
 

Any Api on win NT to get thread handle from thread id?.

Post by Christian » Thu, 15 Jun 2006 13:15:23

Ah, I guess that's it (although if it were, setting it would not be that
much of strange code (undocumented structure, flag, exception - setting the
name in the TIB directly would be easier...)

I just tried VC6's thread window, and it did not show the thread name, it
does not even have a column for it. And the article you mention says
something about the menu item "Debug > Windows >...", I don't have a submenu
"Windows" in "Debug" menu! Do you?

Christian