Last active
March 7, 2024 06:46
-
-
Save npezolano/5477576 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