我正在尝试获得以下成员函数:
void partitionGenerator::parallelGens(unsigned int& count, unsigned int low, unsigned int high, map<unsigned int, unsigned int> & partMap){
partMap.clear();
count = 0;
unsigned int pval;
for(unsigned int i = high ; i >= low ; i--){
pval = geomVal(i);
if(pval!=0){
partMap.insert(make_pair(i, pval));
count+=i*pval;
}
}
}
由以下函数调用:
map<unsigned int, unsigned int> partitionGenerator::parallelGen(unsigned int numthreads){
if(numthreads > 4 || numthreads == 0){
cout << "Max 4 threads" ;
exit(0);}
unsigned int* total = new unsigned int[numthreads];
map<unsigned int, unsigned int> * threadmaps = new map<unsigned int, unsigned int>[numthreads];
map<unsigned int, unsigned int> results;
do{
genArr();
thread* mythreads = new thread[];
for(unsigned int i = 0 ; i < numthreads ; i++)
mythreads[i] = thread(parallelGens,ref(total[i]),i*target/numthreads,(i+1)*target/numthreads-1+(i+1)/numthreads,ref(threadmaps[i]));
for(unsigned int i = 0 ; i < numthreads ; i++)
mythreads[i].join();
}while(sumArr(total,numthreads) != target);
for(unsigned int i = 0 ; i < numthreads ; i++)
results.insert(threadmaps[i].begin() , threadmaps[i].end());
delete[] total;
delete[] threadmaps;
return results;
}
但是,每次我尝试运行程序时,只创建第一个线程,并且在线程执行其他任何操作之前,程序崩溃并且我得到错误R6010 - 已经调用了abort()。
有什么我做错的事情显然很明显吗?这让我感到很沮丧。