Subject: Re: [boost] Adding an option to set the name of a boost::thread
From: Lars Viklund (zao_at_[hidden])
Date: 2012-11-06 14:03:24
On Tue, Nov 06, 2012 at 12:50:23PM -0600, david.hagood_at_[hidden] wrote:
> Has any thought been given to allowing a name to be set on a
> boost::thread, such that (if the underlying implementation supports it)
> that name would show up in things like top and ps?
> In Linux, you can name a thread via the prctl() call and it will show up
> in top - dandy for debugging which of the bazillion threads in my app has
> decided to suck up all the CPU.
> I don't know if Windows supports such a call, and IMHO it would be
> acceptable if the call did nothing in such a case.
> Ideally, I'd want to see it as a property, something like:
> void boost::thread::set_name(std::string name)
> std::string boost::thread::get_name() const;
On VC++, the following names a thread.
const DWORD MS_VC_EXCEPTION=0x406D1388;
inline void SetThreadName(DWORD dwThreadID, char const* threadName)
typedef struct tagTHREADNAME_INFO
DWORD dwType; // Must be 0x1000.
LPCSTR szName; // Pointer to name (in user addr space).
DWORD dwThreadID; // Thread ID (-1=caller thread).
DWORD dwFlags; // Reserved for future use, must be zero.
info.dwType = 0x1000;
info.szName = threadName;
info.dwThreadID = dwThreadID;
info.dwFlags = 0;
RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR),
-- Lars Viklund | zao_at_[hidden]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk