static T MultiplyElement(const Matrix& matrixA, const Matrix& matrixB,
unsigned M2col, unsigned M1row)
{
T sumToReturn = 0;
for (unsigned iM1colM2row = 0; iM1colM2row < matrixA.m_n; iM1colM2row++)
{
sumToReturn +=
matrixA.m_data[M1row][iM1colM2row] * matrixB.m_data[iM1colM2row][M2col];
}
return sumToReturn;
}
...
std::vector<std::thread> threads;
for(unsigned i = 0; i < outM ; ++i)
{
for(unsigned j = 0; j < outN; ++j)
{
threads.push_back(std::thread([&]()
{
outMatrix.m_data[i][j] = MultiplyElement(matrixA, matrixB, i, j);
}
));
}
}
for(auto& thread : threads)
{
thread.join();
}
编译:clang++ -std=c++11 -stdlib=libc++ newFile.cpp
我在 MultiplyElement 中遇到了段错误……知道为什么吗?