当前位置:   article > 正文

C++ 设置线程名字_c++线程名

c++线程名

使用 std::thread

#include <thread>
#include <pthread.h>

std::thread t(funs, args);
pthread_setname_np(t.native_handle(), threadName);
  • 1
  • 2
  • 3
  • 4
  • 5

通过 pthread_create 创建

#define _GNU_SOURCE  
#include <pthread.h>

pthread_t tid;
pthread_create(&tid, NULL, func, NULL);
pthread_setname_np(tid, threadName)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

通过 prctl

prctl(PR_SET_NAME, thdName);
  • 1

注意: 线程名字字符最多16个

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/153551?site
推荐阅读
相关标签
  

闽ICP备14008679号