Skip to content

Instantly share code, notes, and snippets.

@lijiansong
Forked from npezolano/gist:5477576
Created August 23, 2023 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lijiansong/47abc6063f1503b57d6d9efc36ddb287 to your computer and use it in GitHub Desktop.
Save lijiansong/47abc6063f1503b57d6d9efc36ddb287 to your computer and use it in GitHub Desktop.
Changing the thread name on C++11
#include <thread>
#include <iostream>
#include <pthread.h>
using namespace std;
void foo()
{
string s = "thread1";
char name[16];
pthread_setname_np(pthread_self(), s.c_str()); // set the name (pthread_self() returns the pthread_t of the current thread)
pthread_getname_np(pthread_self(), &name[0], sizeof(name));
cout << name << endl;
}
int main()
{
thread t1(foo);
t1.join();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment