将参数传递给线程函数ctpl

时间:2019-11-24 22:49:46

标签: c++ multithreading function arguments parameter-passing

我有一个关于将参数传递给推入线程池的函数的问题。线程池的实现位于以下链接:CTPL THREAD POOL LIBRARY

    void product(Square square){
        cout << " Mat:" << square.a1 << " " <<  square.a2 << " " <<  square.b1 << " " <<  square.b2 << endl;

        for(int i=square.a1;i<square.b1;i++){
            for(int j=square.a2;j<square.b2;j++){
                for (int k = 0; k<matSqrSize;k++)
                {
                    matrixProd[i][j] += matrix1[k][j] * matrix2[i][k];
                }
            }
        }
    }


    int main() {

        ctpl::thread_pool p(threadsNo);

        matrix1 = matrixInit(matrix1);
        matrix2 = matrixInit(matrix2);
        matrixProd = matrixInit(matrixProd);

        matrix1 = randomSet(matrix1);
        matrix2 = randomSet(matrix2);

        for(int i = 1;i <= threadsNo; i++){
            for(int j = 1;j<= threadsNo;j++) {
                int a1 = (i - 1) * (matSqrSize / threadsNo);
                int a2 = i * matSqrSize / threadsNo;
                int b1 = (j - 1) * matSqrSize / threadsNo;
                int b2 = j * matSqrSize / threadsNo;
                Square sq;
                sq.a1 = a1;
                sq.a2 = a2;
                sq.b1 = b1;
                sq.b2 = b2;
                p.push(product,sq);
            }
        }

    matrixPrint(matrixProd);

具体来说,行

p.push(product,sq);

显示错误,表明此功能没有匹配的候选对象。

我很乐意看到您解决这个问题的方法,并祝大家愉快!

0 个答案:

没有答案