[thread] Obtaining thread id on Windows
I'm using Boost.Thread to create a thread that process the message queue on Windows. In order to send it a message via PostThreadMessage I need a thread id rather than a handle. Is there a way to obtain the native thread id from a boost::thread ? If not, any help on how to patch my local copy of the library? There is no documented way of getting a thread id from a thread handle in Windows XP. Thank you. Agustín K-ballo Bergé.-
local copy of the library? There is no documented way of getting a thread id from a thread handle in Windows XP.
From within the thread, you may be able to use ::GetCurrentThreadId()
-- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
If you cannot store the thread ID when the thread is created, the best way (in my experience) to get the thread ID is to have the thread itself store it in a predetermined location when the thread starts up (using Ray's suggestion of GetCurrentThreadId()). John
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Ray Burkholder Sent: Wednesday, September 09, 2009 2:10 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [thread] Obtaining thread id on Windows
local copy of the library? There is no documented way of getting a thread id from a thread handle in Windows XP.
From within the thread, you may be able to use ::GetCurrentThreadId()
-- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-----Original Message----- From: John Wilkinson [mailto:jwilkinson@tsystem.com] Sent: Wednesday, September 09, 2009 2:50 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [thread] Obtaining thread id on Windows
If you cannot store the thread ID when the thread is created, the best way (in my experience) to get the thread ID is to have the thread itself store it in a predetermined location when the thread starts up (using Ray's suggestion of GetCurrentThreadId()).
If you have a window associated with the thread, then you can use the easier function GetWindowThreadProcessId. Otherwise you can use NtQueryInformationThread, although it may be simpler to store the thread ID on creation. See http://www.codeguru.com/forum/showthread.php?t=355572 for an example using NtQueryInformationThread. It's a good guess that GetThreadId is a wrapper for NtQueryInformationThread. -- Bill --
Igor R escribió:
There is no documented way of getting a thread id from a thread handle in Windows XP.
If you mean Win API, there's GetThreadID(handle) function.
Such function does not exist on Windows XP. There is no documented way on Windows XP. Here is some more information: http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/89728ee1-d9d8... Agustín K-ballo Bergé.-
From the MSDN library - Platform SDK: DLLs, Processes, and Threads
GetProcessIdOfThread DWORD GetProcessIdOfThread( HANDLE Thread ); -Rob Yull -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Agustín K-ballo Bergé Sent: Wednesday, September 09, 2009 3:08 PM To: boost-users@lists.boost.org Subject: [Boost-users] [thread] Obtaining thread id on Windows I'm using Boost.Thread to create a thread that process the message queue on Windows. In order to send it a message via PostThreadMessage I need a thread id rather than a handle. Is there a way to obtain the native thread id from a boost::thread ? If not, any help on how to patch my local copy of the library? There is no documented way of getting a thread id from a thread handle in Windows XP. Thank you. Agustín K-ballo Bergé.- _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Cut and pasted the wrong function before GetThreadId DWORD GetThreadId( HANDLE Thread ); -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Rob Yull Sent: Wednesday, September 09, 2009 3:33 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [thread] Obtaining thread id on Windows
From the MSDN library - Platform SDK: DLLs, Processes, and Threads
GetProcessIdOfThread DWORD GetProcessIdOfThread( HANDLE Thread ); -Rob Yull -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Agustín K-ballo Bergé Sent: Wednesday, September 09, 2009 3:08 PM To: boost-users@lists.boost.org Subject: [Boost-users] [thread] Obtaining thread id on Windows I'm using Boost.Thread to create a thread that process the message queue on Windows. In order to send it a message via PostThreadMessage I need a thread id rather than a handle. Is there a way to obtain the native thread id from a boost::thread ? If not, any help on how to patch my local copy of the library? There is no documented way of getting a thread id from a thread handle in Windows XP. Thank you. Agustín K-ballo Bergé.- _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (6)
-
Agustín K-ballo Bergé
-
Bill Buklis
-
Igor R
-
John Wilkinson
-
Ray Burkholder
-
Rob Yull