- 论坛徽章:
- 0
|
在学习使用pthread_create函数创建线程时候,为了查看是否创建成功,写了这样一个程序
#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
#include "pthread.h"
int thread(void)
{
pthread_t newthid;
newthid=pthread_self();
printf("this is a new thread,thread ID =%u\n",newthid);
return 0;
}
int main(void)
{
pthread_t thid;
printf("main thread,ID is %u\n",pthread_self());
if(pthread_create(&thid,NULL,(void*(*)(void *))thread(),NULL)!=0)
{
printf("thread creation failed\n");
exit(1);
}
sleep(1);
exit(0);
}
在编译的时候也加了链接库了,编译是没有问题的,但是我运行的时候
程序没有提示未创建起新线程,但是我在线程函数里得到的线程ID和主函数得到的线程ID值是相同的,而且在末尾系统自动提示"段错误“请问这是啥问题? |
|