
I've found a need to retrieve a thread id rather than a thread handle on Windows. There is no documented way to get it from the handle on XP (see http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/89728ee1-d9d8... ). Would it make sense to add a get_native_id member function? Thank you. Agustín K-ballo Bergé.-

2009/9/10 Agustín K-ballo Bergé <kaballo86@hotmail.com>:
I've found a need to retrieve a thread id rather than a thread handle on Windows. There is no documented way to get it from the handle on XP (see http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/89728ee1-d9d8... ). Would it make sense to add a get_native_id member function?
boost::thread and std::thread don't know what the native thread type is, nor do they know that Windows has two native thread types. The correct solution seems to be: struct native_handle_type { HANDLE handle; DWORD id; // perhaps, for backward compatibilty operator HANDLE() { return handle; } }; In other words it's a QOI detail. Yechezkel Mett

Yechezkel Mett escribió:
2009/9/10 Agustín K-ballo Bergé <kaballo86@hotmail.com>:
Would it make sense to add a get_native_id member function?
boost::thread and std::thread don't know what the native thread type is, nor do they know that Windows has two native thread types.
I don't see them as two native thread types. Windows thread id is consistent with boost::thread::id, while a thread handle isn't. I'm not experienced with threads other than Windows, but it may just happen that in other apis a thread id and a thread handle are exactly the same thing. Compared to C's files, I think of a thread id as the filename and a thread handle as a FILE*. You can't fread from a filename just as you can't suspend/resume a thread id. I don't expect a way to check if two different FILE*s are indeed handles to the same file. And I understand why I can't get a thread id from a thread handle, just as I can't get a filename from a FILE*. I just wonder if, since its there, it would make sense to make it available. I do think its odd for PostThreadMessage to require an id rather than a handle. Nevertheless, I've just added a DWORD and a thread::barrier to my class just to be able to use it, while the value I want is lying there in Boost.Threads internals. I am by no means an expert, so please correct me if I'm wrong. Thank you. Agustín K-ballo Bergé.- PS: I've just checked a Pthreads implementation reference online that provides pthread_getunique_np/pthread_getthreadid_np (non portable) as ways to obtain a native thread id.
participants (2)
-
Agustín K-ballo Bergé
-
Yechezkel Mett