小编Can*_*ini的帖子

c ++使用std库进行多线程处理:比预期慢

我尝试使用std库,特别是线程库.我们的想法是在有多线程和无多线程的情况下填充矩阵.我有8个核心.

void fillMatrix(int ID, std::vector<std::vector<double>> & lMatrix,int inThread){

    for (int i = 0; i < 10000; ++i){
        if (i % inThread == ID){
            for (int j = 0; j < 10000; ++j){
                lMatrix[i][j] = 123456.0;
            }
        }
    }

}


void testMT(int inThread){

    std::vector<std::thread> lPool;
    std::vector<std::vector<double>> lMatrix(10000, std::vector<double>(10000));

    for (int i = 0; i < inThread; ++i){
        lPool.push_back(std::thread(std::bind(&fillMatrix,i, lMatrix,inThread)));
    }

    for (std::thread & t : lPool){
        t.join();
    }
}
Run Code Online (Sandbox Code Playgroud)

主要代码:

int main(){
    const clock_t begin_time1 = clock();
    testMT(1);
    std::cout << float(clock() …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading

1
推荐指数
1
解决办法
240
查看次数

C++ std :: bind to std :: function,VS2015出了什么问题?

我是VS2013的用户,我经常使用如下的初始化,它就像一个魅力:

MyClass::MyClass myRoutine(){
    std::function<double(double)> oFunc = std::bind(&Myclass::myfunction, this, std::placeholders::_1);
}

MyClass::MyClass myfunction(double & inX){
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我决定升级到VS2015,但编译器报告错误:

错误C2440:'初始化':无法从'std :: _ Binder <std :: _ Unforced,double(__ thiscall MyClass ::*)(double&),MyClass*const,const std :: _ Ph <1>&>'转换为'std :: function <double(double)>'

发生了什么?

c++ stl c++11 visual-studio-2013 visual-studio-2015

0
推荐指数
1
解决办法
279
查看次数