C 指针错误&;应为多线程‘;无效*(*)(无效*)&x2019;但参数的类型为‘;pthread_t’;
这段代码检查数独,用多线程。 编译后运行程序时: 分段故障(堆芯转储) 和错误:C 指针错误&;应为多线程‘;无效*(*)(无效*)&x2019;但参数的类型为‘;pthread_t’;,c,multithreading,C,Multithreading,这段代码检查数独,用多线程。 编译后运行程序时: 分段故障(堆芯转储) 和错误: 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
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参数:void*sub();
很抱歉,我的英语不好这是
pthread\u 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.
然后使用该函数作为参数
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;
}
您需要作为第三个参数传递一个函数(返回void*并接受void*类型的1个参数),该函数将接收一个指针,您基本上必须将该指针转换回调用pthread\u create
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;
}