I'd line to use pthread_setname_np
function if it's available. Code from the manpage:
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <pthread.h>
int pthread_setname_np(pthread_t thread, const char *name);
int pthread_getname_np(pthread_t thread,
char *name, size_t len);
Is it safe to just do like that (no includes, no defines):
#ifdef _GNU_SOURCE
pthread_setname_np(pthread_self(), "mythread");
#endif
Includes are not needed because the C++ #include <thread>
that I use seems to pull pthreads
. The _GNU_SOURCE
is always enabled in libstdc++
, and if it gets disabled - the code will still compile.
Am I missing something?