xref: /llvm-project/lldb/test/API/tools/lldb-server/thread-name/main.cpp (revision a2e61bc2f3bc66124575c0abf9b8421073470202)
1 #include <pthread.h>
2 #if defined(__OpenBSD__)
3 #include <pthread_np.h>
4 #endif
5 #include <signal.h>
6 
set_thread_name(const char * name)7 void set_thread_name(const char *name) {
8 #if defined(__APPLE__)
9   ::pthread_setname_np(name);
10 #elif defined(__FreeBSD__) || defined(__linux__)
11   ::pthread_setname_np(::pthread_self(), name);
12 #elif defined(__NetBSD__)
13   ::pthread_setname_np(::pthread_self(), "%s", const_cast<char *>(name));
14 #elif defined(__OpenBSD__)
15   ::pthread_set_name_np(::pthread_self(), name);
16 #endif
17 }
18 
main()19 int main() {
20   set_thread_name("hello world");
21   raise(SIGINT);
22   set_thread_name("goodbye world");
23   raise(SIGINT);
24   return 0;
25 }
26