当前位置: 代码迷 >> 综合 >> invalid conversion from ‘void*’ to ‘void* (*)(void*)’ 问题解决
  详细解决方案

invalid conversion from ‘void*’ to ‘void* (*)(void*)’ 问题解决

热度:2   发布时间:2024-01-16 08:18:17.0
pthread.cpp: In function ‘void thread1(char*)’:
pthread.cpp:11: error: invalid conversion from ‘const void*’ to ‘void*’
pthread.cpp:11: error:   initializing argument 1 of ‘void pthread_exit(void*)’
pthread.cpp: In function ‘int main()’:
pthread.cpp:24: error: invalid conversion from ‘void*’ to ‘void* (*)(void*)’

pthread.cpp:24: error:   initializing argument 3 of ‘int pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)’


网上找了一个程序联系pthread

原程序

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
void  thread1(char s[])
{
        printf("This is a pthread1.\n");
        printf("%s\n",s);
        pthread_exit(“hello”);  //结束线程,返回一个值。
}


/**************main function ****************/

int main()
{
        pthread_t id1;
        void *a1;
        int i,ret1;
        char s1[]="This is first thread!";
        ret1=pthread_create(&id1,NULL,(void *)thread1,s1);
        if(ret1!=0){
                printf ("Create pthread1 error!\n");
                exit (1);
        }
        pthread_join(i

  相关解决方案