【发布时间】:2016-10-25 11:37:13
【问题描述】:
如果可用,我愿意使用pthread_setname_np 函数。手册页中的代码:
#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);
这样做是否安全(不包含,不定义):
#ifdef _GNU_SOURCE
pthread_setname_np(pthread_self(), "mythread");
#endif
不需要包含,因为我使用的 C++ #include <thread> 似乎拉动了 pthreads。 _GNU_SOURCE 始终在 libstdc++ 中启用,如果它被禁用 - 代码仍将编译。
我错过了什么吗?
【问题讨论】:
-
@BasileStarynkevitch,是的。这是关于控制标准库提供的内容。我有兴趣根据构建的设置方式激活我的程序功能。
-
似乎这个问题被标记为
c,但实际问题讨论了c++。这些是不同的语言。请选择一个。 -
@user3629249,这是关于
glibc的功能测试宏。我根本不会用c或c++来标记它,但我认为C 程序员更熟悉glibc 和Linux(而且C 程序员通常更多)。