您好,我的程序有一个小问题(我想将数组乘以标量)。
基本上我想创建一个线程向量来执行乘法运算符(逐个元素)
代码样本
第一主要实现功能
void mainImplementation(){
vector<thread> threads;
vector< vector<int> > result;
vector< vector<int> > tab;
vector<int> temp;
int row = 0;
int col = 0;
int scalar = 5;
loadDataFromFile(tab,temp,row,col);
int availableThreads = thread::hardware_concurrency();
for(int i = 0; i < row; i++){
for(int j = 0; j < col; j++){
for(int t = 1; i <= availableThreads; t++){
threads.push_back(thread(scalarMultiplication,std::ref(tab),
std::ref(result),std::ref(temp),std::ref(i),std::ref(j),std::ref(scalar)));
}
}
}
}
现在实现标量乘法的函数
void scalarMultiplication(vector< vector<int> >& vtab, vector< vector<int> >& vresult, vector<int>& vtemp, int& i, int& j, int& scalar){
//...implementation
}
我还没有实现这一部分,但是我无法解决一个问题
在行中
threads.push_back(thread(scalarMultiplication,std::ref(tab),
std::ref(result),std::ref(temp),std::ref(i),std::ref(j),std::ref(scalar)));
编译器说那里有一个问题
“错误:没有构造函数std :: thread :: thread的实例与参数列表匹配”。
我似乎无法解决此问题。我确实读过我应该通过引用将变量传递给线程构造函数中的函数,所以我认为这不是问题。我传递给乘法函数6个变量,所以应该没问题,但是我不知道该怎么办... Google也帮不了我,因为我搜索了类似的问题。
在此先感谢您的帮助。
就像我想的那样,Visual Studio Ultimate 2012没有可变参数模板。默认值为,5
因此您需要添加#define
来增加限制(最大值为10
):
#define _VARIADIC_MAX 10
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句