[GD-Windows] Naming threads
Brought to you by:
vexxed72
From: Javier A. <ja...@py...> - 2002-08-29 11:50:08
|
Javier Arevalo <ja...@py...> wrote: > We use the undocumented MSVC++ 6 trick for assigning names to > threads (cool!) so we can identify those in the debugger Some people asked me about this, so here's the code: void BASE_SetThreadName(const char *pszName, unsigned threadId) { // 10 chars maximum length of name. char buf[10]; strncpy(buf, pszName, sizeof(buf)); buf[sizeof(buf)-1] = '\0'; enum { MS_VC_EXCEPTION = 0x406d1388 }; struct THREADNAME_INFO { DWORD dwType; // must be 0x1000 LPCSTR pszName; // pointer to name (in same addr space) DWORD dwThreadID; // thread ID (-1 caller thread) DWORD dwFlags; // reserved for future use, most be zero }; THREADNAME_INFO info; info.dwType = 0x1000; info.pszName = pszName; info.dwThreadID = threadId? threadId : ::GetCurrentThreadId(); info.dwFlags = 0; __try { RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(DWORD), (DWORD *)&info); } __except (EXCEPTION_CONTINUE_EXECUTION) { } } In the Debug | Threads dialog you can now see the names of the threads. Javier Arevalo Pyro Studios |