|
Boost Users : |
Subject: Re: [Boost-users] Get "Native" thread id - feature request
From: Zachary Turner (divisortheory_at_[hidden])
Date: 2009-11-05 11:40:14
On Thu, Nov 5, 2009 at 10:30 AM, Ondrej Sluciak <
ondrej.sluciak_at_[hidden]> wrote:
> 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.
>
Most OSes don't even have the concept of thread names, so unfortunately
there's no way to do that portably. I think your best bet is this:
a) Use LoadLibrary and GetProcAddress to check if the function GetThreadId()
exists. If it does, use it. If it doesn't, then:
b) Use LoadLibrary and GetProcAddress to load NtQueryInformationThread.
Search online (maybe in the ReactOS source code) to find the exact signature
of the function and structure layout of the output parameter.
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