如何解决与线程函数在Linux中接受void有关的错误?
我在Linux中遇到错误,提示:
在server.c:7包含的文件中:/usr/include/pthread.h:200:15:注意:预期为'void *()(void *)',但参数的类型为'void()(int )'200 |无效*(__ start_routine)(无效*),| ~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~ –
我知道线程函数必须接受单个void *参数并返回void *。接受任何其他参数是一个错误。返回任何其他结果是错误。我对如何格式化以下代码以纠正错误感到困惑。
这是导致错误的代码:
if(pthread_create( &thread_id,NULL,func,(void*) &connfd) < 0)
{
perror("could not create thread");
}
Here is the definition of func:
void func(int *sockfd)
{
char buff[MAX];
int n;
// infinite loop for chat
for (;;) {
bzero(buff,MAX);
// read the message from client and copy it in buffer
read(*sockfd,buff,sizeof(buff));
// print buffer which contains the client contents
printf("From client: %s\t To client : ",buff);
bzero(buff,MAX);
n = 0;
// copy server message in the buffer
while ((buff[n++] = getchar()) != '\n');
// and send that buffer to client
write(*sockfd,sizeof(buff));
// if msg contains "Exit" then server exit and chat ended.
if (strncmp("exit",4) == 0) {
printf("Server Exit...\n");
break;
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。