Boost logo

Boost Users :

Subject: Re: [Boost-users] Get "Native" thread id - feature request
From: Ondrej Sluciak (ondrej.sluciak_at_[hidden])
Date: 2009-11-05 11:30:30


Thank you for your hints. Well, it isn't just question of SetThreadName
function on Windows. The ability to get the real thread id is quite
crucial when you want to debug or when you want to log also thread
behaviour. On linux you are also interested in real pids. I mean it
would be really great if you could also set thread names (and get thread
names) directly using boost (and not using those undocumented windows
functions), but I don't know if there is some general way how to do it
on any OS, so I don't know if it would be "feasible" to put it in boost.
On the other hand, getting only thread ids can be done on any OS (as far
as I know). So at least this functionality would be nice to have in boost.

Zachary Turner wrote:
>
>
> On Thu, Nov 5, 2009 at 9:02 AM, Ondrej Sluciak
> <ondrej.sluciak_at_[hidden]
> <mailto:ondrej.sluciak_at_[hidden]>> wrote:
>
>
> Hello, is there a way how to get the thread id that system assigns
> to thread? I mean the id that is located in "thread_info->id". It
> would quite nice if boost could return this value, because for
> example if I want to set name of the thread on windows using
> function SetThreadName(), I need exactly that id. In my
> application I would have to add this "feature" directly to
> boost::thread.hpp, which is not very nice solution.
> I know that also GetThreadName(myThread->native_handle()) should
> work, but if I do it like this I always get a Windows error "The
> procedure entry point GetThreadId could not be located in the
> dynamic link library KERNEL32.dll". And I also guess, that this
> new "feature" wouldn't destroy the overall design of boost::thread
> architecture. To get the "real" thread id is in my opinion in
> general a useful thing.
>
>
> The reason is that GetThreadId only exists on 2003/Vista+. There is
> an undocumented way to do what you want, and it requires using
> NtQueryInformationThread which is undocumented. To use it you need to
> manually LoadLibrary / GetProcAddress. The output parameter of this
> function is another undocumented structure which contains the thread
> id. Nevertheless, look into it and I think you'll find at least
> something that works, even if it's ugly.
>
> That being said, I agree the thread id is important sometimes, if we
> have ability to get the handle there's no reason we shouldn't have the
> ability to get the id also.
> ------------------------------------------------------------------------
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net