Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ g++;编译器:错误-从';pthread_t{aka long unsigned int}';至';无效*(*)(无效*)&x27;[-fpermissive]_C++_Compilation_Pthreads - Fatal编程技术网

C++ g++;编译器:错误-从';pthread_t{aka long unsigned int}';至';无效*(*)(无效*)&x27;[-fpermissive]

C++ g++;编译器:错误-从';pthread_t{aka long unsigned int}';至';无效*(*)(无效*)&x27;[-fpermissive],c++,compilation,pthreads,C++,Compilation,Pthreads,我试图在命令行上编译我的程序,但我遇到了这个错误。它指向以下代码中的pthread_create行。我有正确的pthreads导入,我在Ubuntu上运行,所以我知道这不是问题所在。否则,我对发生的事一无所知 int main() { pthread_t thinker; if(pthread_create(&thinker, NULL, thinker, NULL)) { perror("ERROR creating thread."); }

我试图在命令行上编译我的程序,但我遇到了这个错误。它指向以下代码中的pthread_create行。我有正确的pthreads导入,我在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\u例程)(void*)
不兼容。它应该是函数指针。应该是:

void *callback_function( void *ptr ){}

pthread_create(&thinker, NULL, callback_function, NULL)

线程创建的签名为:

int pthread_create(pthread_t * thread, 
                       const pthread_attr_t * attr,
                       void * (*start_routine)(void *), 
                       void *arg);
如果在代码中看到,则将
thinker
作为第三个参数传递,该参数与
void*(*start\u例程)(void*)
不兼容。它应该是函数指针。应该是:

void *callback_function( void *ptr ){}

pthread_create(&thinker, NULL, callback_function, NULL)

线程创建的签名为:

int pthread_create(pthread_t * thread, 
                       const pthread_attr_t * attr,
                       void * (*start_routine)(void *), 
                       void *arg);
如果在代码中看到,则将
thinker
作为第三个参数传递,该参数与
void*(*start\u例程)(void*)
不兼容。它应该是函数指针。应该是:

void *callback_function( void *ptr ){}

pthread_create(&thinker, NULL, callback_function, NULL)

线程创建的签名为:

int pthread_create(pthread_t * thread, 
                       const pthread_attr_t * attr,
                       void * (*start_routine)(void *), 
                       void *arg);
如果在代码中看到,则将
thinker
作为第三个参数传递,该参数与
void*(*start\u例程)(void*)
不兼容。它应该是函数指针。应该是:

void *callback_function( void *ptr ){}

pthread_create(&thinker, NULL, callback_function, NULL)


线程启动时应该做什么?为什么要使用pthreadsapi?现在是2015年。我们已经有了
std::thread
很久了,在那之前的
boost::thread
很久了。
void*(*)(void*)
是一个指向函数的指针,而你正试图传递一个整数值。“否则,我对发生的事情一无所知。”是的,我们也是。你忘了告诉我们你想做什么。我很抱歉大家。这是一个学校项目,几乎没有解释pthreads,我们需要使用它们,这不是一个选择:(thinker方法分解字符串输入并对其进行验证。之后,其中还有其他线程对该输入执行其他操作。当线程启动时,您的线程应该做什么?为什么要使用pthreads API?现在是2015年。在这之前,我们已经有了
std::thread
多年了,而
boost::thread
多年了。
void>*(*)(void*)
是一个指向函数的指针,当你试图传递一个整数值时,“否则,我对发生的事情一无所知。”是的,我们也是。你忘了告诉我们你想做什么。我很抱歉大家。这是一个学校项目,几乎没有解释pthreads,我们需要使用它们,这不是一个选择:(thinker方法分解字符串输入并对其进行验证。之后,其中还有其他线程对该输入执行其他操作。当线程启动时,您的线程应该做什么?为什么要使用pthreads API?现在是2015年。在这之前,我们已经有了
std::thread
多年了,而
boost::thread
多年了。
void>*(*)(void*)
是一个指向函数的指针,当你试图传递一个整数值时,“否则,我对发生的事情一无所知。”是的,我们也是。你忘了告诉我们你想做什么。我很抱歉大家。这是一个学校项目,几乎没有解释pthreads,我们需要使用它们,这不是一个选择:(thinker方法分解字符串输入并对其进行验证。之后,其中还有其他线程对该输入执行其他操作。当线程启动时,您的线程应该做什么?为什么要使用pthreads API?现在是2015年。在这之前,我们已经有了
std::thread
多年了,而
boost::thread
多年了。
void>*(*)(void*)
是一个指向函数的指针,当你试图传递一个整数值时,“否则,我对发生的事情一无所知。”是的,我们也是。你忘了告诉我们你想做什么。我很抱歉大家。这是一个学校项目,几乎没有解释pthreads,我们需要使用它们,这不是一个选择:(thinker方法分解字符串输入并对其进行验证。之后,它内部还有其他线程对该输入执行其他操作。实际上,我将thinker作为一个void*函数,就像这样。它被称为:void*thinker(void*parm){}…但我想我刚刚意识到我的问题是我的pthread和我的方法同名…我将尝试更改其中一个,看看它是否有效…这就是问题所在。感谢您指出错误。我是否应该删除此帖子,因为这是一个小错误,与pthread或任何特别的东西无关?@user2872777如果有人会犯同样的错误,这会很有帮助。只要把它标记为正确。实际上,我把思考者作为一个void*函数,就像这样。它被称为:void*思考者(void*parm){}…但我想我刚刚意识到我的问题是我的pthread和我的方法同名…我将尝试更改其中一个,看看它是否有效…这就是问题所在。感谢您指出错误。我是否应该删除此帖子,因为这是一个小错误,与pthread或任何特别的东西无关?@user2872777如果有人会犯同样的错误,这会很有帮助。只要把它标记为正确。实际上,我把思考者作为一个void*函数,就像这样。它被称为:void*思考者(void*parm){}…但我想我刚刚意识到我的问题是我的pthread和我的方法同名…我将尝试更改其中一个,看看它是否有效…这就是问题所在。感谢您指出错误。我是否应该删除此帖子,因为这是一个小错误,与pthread或任何特别的东西无关?@user2872777如果有人会犯同样的错误,这会很有帮助。只需将其标记为正确。实际上,我有一个类似void*函数的thinker。它的名称是:void*thinker(void*parm){}…但我想我刚刚意识到我的问题是我的pthread和我的method