std :: thread构造函数(变量数量)

论文

您好,我的程序有一个小问题(我想将数组乘以标量)。

基本上我想创建一个线程向量来执行乘法运算符(逐个元素)

代码样本

第一主要实现功能

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也帮不了我,因为我搜索了类似的问题。

在此先感谢您的帮助。

杰西·古德(Jesse Good)

就像我想的那样,Visual Studio Ultimate 2012没有可变参数模板。默认值为,5因此您需要添加#define来增加限制(最大值为10):

#define _VARIADIC_MAX 10

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

'std :: thread'如何确定传递给构造函数的可变参数的数量

没有参数的std :: thread构造函数

std :: vector是否具有{元素的初始数量}构造函数?

std :: thread通过引用传递调用复制构造函数

通过(Args && ...)构造std :: thread

std :: thread的构造和执行

std可选复制构造函数

构造函数使用std :: forward

在C ++中将通用构造函数分配给成员变量时,std :: move或std :: forward

C ++ / Threading:没有构造函数“ std :: thread :: thread”的实例>匹配参数列表

没有构造函数“ std :: thread :: thread”的实例与参数列表匹配

在没有复制构造函数的对象的成员函数中启动 std::thread

使用删除的函数'std :: thread :: thread(const std :: thread&)'

`std::thread` 对象的构造函数中的 `decay_copy` 有什么作用?

std :: thread构造函数第三个模板参数的目的是什么?

std :: thread构造函数传递指针和ref传递之间有区别吗?

将对临时/匿名lambda的const引用传递到std :: thread构造函数中是否安全?

std::thread 是否对其构造函数返回时发生的事情做出任何保证?

C++ - 我如何能够为 std::thread 调用复制构造函数?

默认构造函数std :: thread :: id不应该创建一个“ NULL” id吗?

vscode中的C ++:错误:没有匹配的构造函数来初始化'std :: thread'

没有合适的构造函数可以从void转换为std:thread

std::thread 构造函数完成实际上与执行线程的开始同步吗?

std :: thread初始化构造函数给出了编译错误

对于以std :: thread和std :: mutex为字段的类,move构造函数是否有意义?

根据构造函数字符串文字声明std :: array成员变量的大小

在不使用std :: forward的情况下如何调用成员变量的move构造函数?

构造函数采用std :: string_view与std :: string并移动

为什么std :: optional构造函数使用std :: in_place?