-
-
Save lijiansong/47abc6063f1503b57d6d9efc36ddb287 to your computer and use it in GitHub Desktop.
Changing the thread name on C++11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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