10 개의 스레드를 생성하고 정상적으로 실행하는 프로그램을 작성했습니다. 프로그램이 잘 실행되고 있지만 결국에는 세그먼트 오류가 발생합니다. 이 결함은 무엇이며, 그 원인은 무엇이며 어떻게 해결합니까? 내 코드는 다음과 같습니다프로그램 실행 중 세그먼트 오류
#include<stdio.h>
#include<pthread.h>
void *print(void *num);
int main()
{
pthread_t tid[10];
int n,check;
void *exitstatus;
for(n=1;n<=10;n++)
{
check=pthread_create(&tid[n],NULL,print,(void *)&n);
if(check=0)
printf("thread created");
pthread_join(tid[n],&exitstatus);
}
return 0;
}
void *print(void *num)
{
int i,*val=(int *)num;
for(i=0;i<(5);i++)
printf("Hello World!!!(thread %d)\n",*val);
}
gdb를 사용하여 오류의 원인을 찾아 냈습니까? – ziu