pthreads错误:类型的参数“ void *( *)()();是不兼容的
我不太确定该如何调试,我对线程是全新的,并且正在遵循100%有效的教程,但对我来说不适用:
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
void* sample() {
printf("Thread sample. \n");
}
int main(void) {
// Thread Creation
pthread_t tid; // Creation of thread pointer.
pthread_create(&tid, NULL, &sample, NULL); // Creation of thread.
// Waiting for threads to be completed:
pthread_join(tid, NULL);
return 0;
}
我收到错误:类型“ void 的参数() ()“与“ void” ()类型的参数不兼容(void *)
。 com/watch?v = avyejqusfeu“ rel =“ nofollow noreferrer”> https://www.youtube.com/watch?v=voutyejqusfeu
除了我没有打开文件并在线上删除这些内容(因为 在那里。
它不是
I'm not too sure how to debug this, I am completely new to threads and am following a tutorial which worked 100%, but not for me:
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
void* sample() {
printf("Thread sample. \n");
}
int main(void) {
// Thread Creation
pthread_t tid; // Creation of thread pointer.
pthread_create(&tid, NULL, &sample, NULL); // Creation of thread.
// Waiting for threads to be completed:
pthread_join(tid, NULL);
return 0;
}
I get the error: argument of type "void ()()" is incompatible with parameter of type "void ()(void *).
All I am doing is following exactly the tutorial from: https://www.youtube.com/watch?v=aVyeJQuSFEU
Except I did not open the file and delete those things on line 317 (since it wasn't there). But VS recognizes the pthread library now.
Any help is sincerely appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
。代码> void* sample()函数不需要参数,但是您应该以
pthread_create
的方式定义它。 。承诺返回
void*
,但 要解决此问题该教程可以在其在Visual Studio中添加
pthread.h
等的方式是正确的,但是在使用pthread_create()
时是错误。最好找到更有权威的东西。The error is telling you exactly the problem: you defined your
void* sample()
function to take no arguments, but you should define it the waypthread_create
expects:void* sample(void *ptr) {...}
.If you don't need the input
ptr
parameter, you can simply not use it.P.S. There is an additional bug in your
sample()
function: it promised to returnvoid*
, but doesn't. To fix this, addreturn NULL;
.P.P.S. The tutorial may be correct in the way it adds
pthread.h
etc to Visual Studio, but is wrong in its use ofpthread_create()
. You'll be better off finding something more authoritative.