그래서 코드를 실행할 때 pthread_join에서 세분화 오류가 발생합니다. 실행되지 않는 pthread_join 다음에 print 문이 있습니다. 왜 아무 생각 없어? 이 점을 이해하는 방법에 대한 힌트 나 아이디어를 알려주시겠습니까 ??pthread_join에서 세그먼트 오류
출력은 내 행렬의 모든 행 번호를 끝까지 출력 한 다음 matrixCalc 함수를 떠나 "스레드 생성 후"를 인쇄합니다. 이것은 1 스레드에 대한 인수를 넣을 때 발생합니다.
여기 내 코드의 작은 부분을 포함 시켰습니다 :
int main(int argc, char*argv[])
{
//takes in number of threads as 1st arg
pthread_attr_init(&attr);
//initialize matrix here
//passes num of threads through matrixcalc
for(i = 0; i < numberOfThreads; i++)
{
threadCount++;
pthread_create(&tid, &attr, matrixCalc(threadCount), NULL);
}
printf("after threads are created\n");
pthread_join(tid, NULL);
printf("after join\n");
exit(0);
return 0;
}
여기 매트릭스 CALC 기능입니다 :
void *matrixCalc(threadCount)
{
int i, j, sum, tempNum, currentRow;
currentRow = threadCount;
sum=0;
while(currentRow < 1200)
{
//cycles through the column j for matrix B
for(j=0; j<500; j++)
{
//cycles through the diff i values for the set row in matrix A and column in matrix B
for(i=0; i<1000; i++)
{
//Matrix A set i value is at threadcount-1
//Matrix B i value = j
//Matrix B j value = i
//Multiply together and add to sum
tempNum = (matrixA[currentRow-1][i])*(matrixB[i][j]);
sum = sum+tempNum;
}
//Set Matrix C at i value = currentRow and jvalue = i to sum
matrixC[currentRow-1][j] = sum;
//printf("%d\n", matrixC[currentRow-1][i]);
}
//increase threadcount by number of threads
//until you hit max/past max val
currentRow = currentRow + nThreads;
//printf("%d\n", currentRow);
}
return NULL;
}
당신은 –
당신이 matrixCalc 기능을 붙여 넣을 수 ... pthread_create' 실패'여부를 확인해야합니까? – tyilmaz
@BitFiddlingCodeMonkey, x = pthread_create를 설정하고 x! 0,하지만 = 0인지 확인했습니다. – angyxpoo