I have a two-dimensional array (std::array) that is filled by calling a function (predict function of a frugally-deep model) in a two-dimensional nested for-loop and assigning that value to the array. When I call the function without std::async it works just fine but when I call the function with std::async the value is not stored in the array and all the values of the array remain 0 (the value seems to be calculated correctly when I print it out).
void DigitClassifier::addDigitToPredictions(cv::Mat* digit, int* cell)
{
*cell = this->classifyDigit(digit);
//Printing function prints correct value
__android_log_print(ANDROID_LOG_DEBUG, "DigitClassifier", "Classified digit as %d", *cell);
}
void DigitClassifier::classifySudoku(cv::Mat* (&digits)[81], Sudoku &sudoku)
{
for(int row = 0; row < 9; row++)
{
for(int col = 0; col < 9; col++)
{
m_Futures.push_back(std::async(std::launch::async, &DigitClassifier::addDigitToPredictions, this, digits[row + col * 9], &sudoku.m_ScannedDigits[row][col]));
//When I call the function normally everything works just fine
//addDigitToPredictions(digits[row + col * 9], &sudoku.m_ScannedDigits[row][col]);
}
}
SudokuSolver s;
}
I seem to be using std::async or futures.push_back wrong. How do I use them correctly?