• 设置线程名字


    vs2010   https://msdn.microsoft.com/en-us/library/xcb2z8hs(v=vs.100).aspx

     1 const DWORD MS_VC_EXCEPTION=0x406D1388;
     2 
     3 #pragma pack(push,8)
     4 typedef struct tagTHREADNAME_INFO
     5 {
     6     DWORD dwType; // Must be 0x1000.
     7     LPCSTR szName; // Pointer to name (in user addr space).
     8     DWORD dwThreadID; // Thread ID (-1=caller thread).
     9     DWORD dwFlags; // Reserved for future use, must be zero.
    10 } THREADNAME_INFO;
    11 #pragma pack(pop)
    12 
    13 void SetCurrentThreadName(const char* threadName)
    14 {
    15     THREADNAME_INFO info;
    16     info.dwType = 0x1000;
    17     info.szName = threadName;
    18     info.dwThreadID = -1;
    19     info.dwFlags = 0;
    20 
    21     __try
    22     {
    23         RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info );
    24     }
    25     __except(EXCEPTION_EXECUTE_HANDLER)
    26     {
    27     }
    28 }

    linux  https://github.com/apache/trafficserver/blob/f9a6930fca6ea458615fa7fef6b7e67c472701ed/lib/ts/ink_thread.h

     1 // This define is from Linux's <sys/prctl.h> and is most likely very
     2 // Linux specific... Feel free to add support for other platforms
     3 // that has a feature to give a thread specific name / tag.
     4 static inline void
     5 ink_set_thread_name(const char *name ATS_UNUSED)
     6 {
     7 #if defined(HAVE_PTHREAD_SETNAME_NP_1)
     8   pthread_setname_np(name);
     9 #elif defined(HAVE_PTHREAD_SETNAME_NP_2)
    10   pthread_setname_np(pthread_self(), name);
    11 #elif defined(HAVE_PTHREAD_SET_NAME_NP_2)
    12   pthread_set_name_np(pthread_self(), name);
    13 #elif defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_NAME)
    14   prctl(PR_SET_NAME, name, 0, 0, 0);
    15 #endif
    16 }
  • 相关阅读:
    Broadcom BCM94352z/DW1560驱动新姿势
    amd显卡更新最新驱动鼠标顿卡的解决方法
    设置 P2415Q & P2715Q 显示器使其支持 HDMI 2.0 启用 4k@60hz
    Web基础之Redis
    前端基础之AJAX
    Java基础之枚举
    解决Tomcat在idea控制台乱码问题
    JQuery基础
    JavaScript基础笔记
    前端基础之Html、CSS
  • 原文地址:https://www.cnblogs.com/youngt/p/5311650.html
Copyright © 2020-2023  润新知