2015-01-19 1 views
1

이 코드는 다중 스레드와 함께 스도쿠를 검사합니다. 내가 실행 프로그램 컴파일 후 : 분할 오류 (덤프 코어)포인터 및 다중 스레드 예상 오류 'void * (*) (void *)'하지만 인수는 'pthread_t'유형입니다.

int main(){ 
char t0,t1,t2; 

pthread_t row,col,sub1; 

t0=pthread_create(&row,NULL,row,NULL); //eror iz here! 
t1=pthread_create(&col,NULL,col,NULL); 
t2=pthread_create(&sub1,NULL,sub,NULL); 

pthread_join(row, NULL); 
pthread_join(col, NULL); 
pthread_join(sub1, NULL); 

exit(EXIT_SUCCESS); 
return 0; 
} 

및 오류 :

su.c: In function ‘main’: 
su.c:87:2: warning: passing argument 3 of ‘pthread_create’ makes pointer from integer without a cast [enabled by default] 
In file included from su.c:4:0: 
/usr/include/pthread.h:225:12: note: expected ‘void * (*)(void *)’ but argument is of type ‘pthread_t’ 
su.c:88:2: warning: passing argument 3 of ‘pthread_create’ makes pointer from integer without a cast [enabled by default] 
In file included from su.c:4:0: 
/usr/include/pthread.h:225:12: note: expected ‘void * (*)(void *)’ but argument is of type ‘pthread_t’ 

내 FUNC 0 인수를 줄 수 있습니다 : 무효 * 서브를(); 미안하지만, 내 영어가 좋지 않다

답변

2
void * my_row_function(void *param){ 
    Row * myrow = (Row*) param; 
    //bla bla 
} 

int main(){ 
    Row * a_row= & row8outof9; 
    pthread_create(&row,(const pthread_t*)NULL, 
      my_row_function, a_row); 
    return 0; 
} 

당신은, 그 기능은 기본적으로 당신이 전달 된 포인터 형식으로 다시 캐스팅이 포인터를 받게됩니다 세 번째 인수로 함수 통과 (무효 반환 *를 입력합니다 무효 * 1 개 인수를 동의) 할 필요가 전화 할 때 pthread_create

2

프로토 타입 pthread_create입니다.

int pthread_create(pthread_t *thread, const pthread_attr_t *attr, 
         void *(*start_routine) (void *), void *arg); 

이 경우 세 번째 인수는 void 포인터를 반환하는 함수 여야하며 void 포인터를 인수로 사용합니다.

위의 함수를 작성한 다음이를 pthread_create의 세 번째 인수로 전달하십시오.

void * thr_fn2(void *arg)// your function must be like this. 

그런 다음 해당 함수를 인수로 사용하십시오.

관련 문제