您的位置:首页 > 运维架构 > Linux

Problem 58 怎样判断当前程序链接的是多线程版的Glibc还是单线程版的Glibc?

2014-05-12 00:00 781 查看
Problem58 怎样判断当前程序链接的是多线程版的Glibc还是单线程版的Glibc
Ans:
在Linux程序设计当中,如果一个程序被设计成可以支持单线程或多线程的模式,可以当过弱引用的方法来判断当前的程序是链接到单线程的Glibc还是多线程的Glibc。具体如下代码所示:
#include <stdio.h>
#include <pthread.h>

int pthread_create(
pthread_t *,
const pthread_attr_t *,
void *(*)(void *),
void *) __attribute__ ((weak));

int main(int argc, char *argv[])
{
if (pthread_create != NULL) {
printf("This is a multi-thread version.\n");
} else {
printf("This is a single-thread version.\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  多线程 linux null
相关文章推荐