pthread_create没有参数? [英] pthread_create with no arguments?
本文介绍了pthread_create没有参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个没有函数参数的线程,但我一直遇到严重困扰我的错误,因为我无法获得一些超级简单的方法来正确工作
I want to create a thread with no function arguments but I keep getting errors that are seriously bugging me because I cant get something super simple to work right
这里是我的代码:
#include<stdio.h>
#include<array>
#include<pthread.h>
#include<fstream>
#include<string>
void *showart(NULL);
int main(int argc, char** argv){
pthread_t thread1;
pthread_create( &thread1, NULL, showart, NULL);
getchar();
return 0;
}
void *showart(NULL)
{
std::string text;
std::ifstream ifs("ascii");
while(!ifs.eof())
{
std::getline(ifs,text);
printf(text.c_str());
}
}
它给出了错误:
main.cpp:11:50: error: invalid conversion from ‘void*’ to ‘void* (*)(void*)’ [-fpermissive]
推荐答案
您的函数必须与pthread匹配.这意味着它需要获取并返回void*
.改为使用void* showart(void*);
.
Your function has to match the pthread one. Meaning it needs to take and return a void*
. Use void* showart(void*);
instead.
这篇关于pthread_create没有参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文