模板类中的std :: thread

时间:2017-08-07 20:12:14

标签: c++ multithreading stdthread

我有一个问题,似乎无法弄清楚这里有什么问题。 我尝试在模板类的静态成员函数中创建许多线程。这里是导致问题的代码片段:

  for(unsigned long rIndex=0; rIndex<pRLength; rIndex+=1){
    for(unsigned long sIndex=0; sIndex<pSLength; sIndex+=1){
      for(unsigned long tIndex=0; tIndex<pTLength; tIndex+=1){
        threads[threadIndex] = std::thread(
          JMatrix<T>::blockByBlockShallow,
          lhs, rhs,
          r, (r+=partitionR[rIndex])-1,
          s, (s+=partitionS[sIndex])-1,
          t, (t+=partitionT[tIndex])-1,
          fanInMatrices[sIndex]
        );
        threadIndex+=1;
        rIndex+=1;
        sIndex+=1;
        tIndex+=1;
      }
    }
  }

blockByBlockShallow是JMatrix模板类的私有静态成员函数。 这里是编译器输出:

g++ -std=c++11 -I./inc -c -o bin/.JMatrix src/jmatrix.cpp -lpthread
In file included from ./inc/jmatrix.hpp:11:0,
                 from src/jmatrix.cpp:1:
/usr/include/c++/7.1.1/thread: In instantiation of 'struct std::thread::_Invoker<std::tuple<void (*)(JMatrix<char>&, JMatrix<char>&, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, JMatrix<char>&), JMatrix<char>, JMatrix<char>, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, JMatrix<char> > >':
/usr/include/c++/7.1.1/thread:127:22:   required from 'std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (&)(JMatrix<char>&, JMatrix<char>&, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, JMatrix<char>&); _Args = {JMatrix<char>&, JMatrix<char>&, long unsigned int&, long unsigned int, long unsigned int&, long unsigned int, long unsigned int&, long unsigned int, JMatrix<char>&}]'
src/jmatrix.cpp:266:32:   required from 'static JMatrix<T> JMatrix<T>::multiplyFanIn(JMatrix<T>&, JMatrix<T>&, long unsigned int*, long unsigned int, long unsigned int*, long unsigned int, long unsigned int*, long unsigned int) [with T = char]'
src/jmatrix.cpp:347:16:   required from here
/usr/include/c++/7.1.1/thread:240:2: error: no matching function for call to 'std::thread::_Invoker<std::tuple<void (*)(JMatrix<char>&, JMatrix<char>&, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, JMatrix<char>&), JMatrix<char>, JMatrix<char>, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, JMatrix<char> > >::_M_invoke(std::thread::_Invoker<std::tuple<void (*)(JMatrix<char>&, JMatrix<char>&, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, JMatrix<char>&), JMatrix<char>, JMatrix<char>, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, JMatrix<char> > >::_Indices)'
  operator()()
  ^~~~~~~~

有什么建议吗?我尝试了几件事,我在这里很失落。提前致谢。

0 个答案:

没有答案