【发布时间】:2013-01-08 17:09:04
【问题描述】:
当我调试我的prj时,我收到此错误:
args 错误:报告多个错误。\ 执行 MI 命令失败:-var-create -
来自调试器后端的args 错误消息:尝试取消引用通用指针。\ 无法创建变量对象
从 void* args 转换为 Mapper* arg 时出现错误。
更新 1
KMaster、KMapper 分别实现了 Master、Mapper 但它们并没有添加任何相关的内容。有效地是致电方法work()的kmapper。代码如下:
int main(){
int np=1,K=4;
string path="lucca.gps";
KMaster* master=new KMaster(path,np,K);
KMapper* mapper[np];
master->splitting();
for(int i=0;i<np;i++){
mapper[i]=new KMapper(master,master->mData[i].key,master->mData[i].value);
while(mapper[i]->work()!=0){
cout<<"failed creating mapper, retry..."<<endl;
sleep(1000);
}
}
}
int KMaster::splitting(){
cout<<"start splitting"<<endl;
fstream is(path.c_str());
string s="";
getline(is,s);
while(!is.eof()){
for(int i=0;i<nProc;i++){
pair<double,double> res;
is>>res.first;
is>>res.second;
is>>s;
mapData[i].push_back(res);
Data.push_back(res);
if(is.eof()) break;
}
}
list<pair<double,double> >::iterator it=Data.begin();
int increment=Data.size()/K;
for(int i=0;i<K;i++){
Klusters.push_back(*it);
advance(it,increment);
}
for(int i=0;i<nProc;i++){
mData[i].key=&Klusters;
mData[i].value=&mapData[i];
}
cout<<"splitting completed"<<endl;
return 0;
}
int Mapper::work(){
Mapper* m=this;
void* p=m;
return pthread_create(&thread,NULL,start,p);
}
void* start(void* args){
cout<<"start()"<<endl;
Mapper* arg= reinterpret_cast<Mapper*>(args);
arg->mapResult=arg->map(arg->k,arg->v);
cout<<"Mapper finish, sending result..."<<endl;
arg->send(arg->mapResult);
}
希望有人能帮忙!
更新 2
调试器截图:
【问题讨论】:
-
为什么不
return pthread_create(&thread,NULL,start,reinterpret_cast<void *>(this));span> -
@ davidschwartz:无需。只需
this即可。 -
顺便说一句:形式上,
start必须声明为extern "C",但这不太可能导致您的错误。 -
你为什么不用
std::thread? -
您确定要在同一个班级进行投射吗?您不会意外地退回到派生度更高的类吗?
标签: c++ void-pointers reinterpret-cast static-cast