繁体   English   中英

g ++编译器:从'pthread_t {aka long unsigned int}'到'void *(*)(void *)'的错误无效转换[-fpermissive]

[英]g++ compiler: error invalid conversion from 'pthread_t {aka long unsigned int}' to 'void* (*)(void*)' [-fpermissive]

我试图在命令行上编译程序,但出现此错误。 它指向以下代码中的pthread_create行。 我有正确的pthread导入,并且我在Ubuntu上运行,所以我知道这不是问题。 否则,我对正在发生的事情一无所知。

int main() {
    pthread_t thinker;
    if(pthread_create(&thinker, NULL, thinker, NULL)) {
         perror("ERROR creating thread.");
    }
    pthread_join(thinker, NULL);
    return 0;
}

线程创建的签名是:

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

如果在代码中看到,则将thinker作为第三个参数传递,该参数与void * (*start_routine)(void *)不兼容。 它应该是函数指针。 它应该是:

void *callback_function( void *ptr ){}

pthread_create(&thinker, NULL, callback_function, NULL)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM