我在我的程序中使用了方法'pthread_create',并在此方法中出现了分段错误。
什么可能导致这种情况?我用正确的参数类型调用这个函数!pthread_create分段错误
这是代码:
pthread_t* _daemon;
void* writer(void* arg){
// stuff that dont involve "arg"...
}
int initdevice(){
if(pthread_create(_daemon, NULL, &writer, NULL) != 0) //seg in this line
{
cerr << "system error\n";
return ERR_CODE;
}
return SUCCESS;
}
int main() {
initdevice();
return 0;
}
注:我试图调用到作家在pthread_create之前也运行它没有“&”,也是 - 我们尝试发送给该方法一些void *参数而不是最后一个NULL参数。
发布你在这个调用中使用的代码,你可能做得不对。 – Mat 2011-04-03 16:53:45
我认为问题出在第17行。 – Nawaz 2011-04-03 16:55:09
不要使用下划线'_'作为全局变量的第一个字符(只是不要在变量的开头使用它们)。 [这些标识符保留给编译器和操作系统](http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-ac-identifier/228797#228797 )。 – 2011-04-03 17:22:47