Changes

Jump to: navigation, search

GPU621/Pragmatic

1,251 bytes added, 14:17, 9 November 2016
Added notes for "How to: Set a Thread Name in Native Code" section
* The ''Suspended Count'' column - displays suspended count value (Suspended count indicates whether a thread is suspended or not. If suspend count value is 0, a thread is NOT suspended);
* The ''Process Name'' column - displays the process name to which each thread belongs;
 
 
'''How to: Set a Thread Name'''
 
Thread name can be set using SetThreadName function provided by Microsoft:
 
#include <windows.h>
...
// This function is taken from https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
// Usage: SetThreadName ((DWORD)-1, "Enter thread name here");
const DWORD MS_VC_EXCEPTION = 0x406D1388;
#pragma pack(push,8)
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.
} THREADNAME_INFO;
#pragma pack(pop)
void SetThreadName(DWORD dwThreadID, const char* threadName)
{
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = threadName;
info.dwThreadID = dwThreadID;
info.dwFlags = 0;
#pragma warning(push)
#pragma warning(disable: 6320 6322)
__try
{
RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR*)&info);
}
__except (EXCEPTION_EXECUTE_HANDLER) {}
#pragma warning(pop)
}
 
'''NOTE:''' When using -1 as a thread identifier argument, a thread that calls this function will have it's name changed as per second argument.
54
edits

Navigation menu