#include
#include
int sum;
void * runner(void * param);
int main(int argc,char * argv[])
{
pthread_t tid;
pthread_attr_t attr;
if(argc<2)
{
printf("the number of paraments shuold more than 1");
return -1;
}
if(atoi(argv[1]<0))
{
printf("the parament should be more than 0");
return -1;
}
pthread_attr_init(&attr);
pthread_create(&tid,&attr,runner,argv[1]);
pthread_attr_destroy(&attr);
pthread_join(tid,NULL);
printf("sum=%d",sum);
}
void * runner(void * param)
{
int i,upper=atoi(param);
sum=0;
for(i=0;i<=upper;i++)
sum+=i;
pthread_exit(0);
}
大神求解答
在終端./main.c 5 輸入後就提示
segmentation fault (core dumped)
直接gdb斷點跟蹤一下,看具體異常的代碼位置,多數是指針越界等