C ++ bug a

  for(int j=0;j<thread_counts;j++) {
    std::vector<std::string> tmp_lines(lines.begin() + tmp_size * j, lines.begin() + tmp_size * (j + 1));
    tmp_threads[j] = std::thread(face_crop_multi, std::ref(tmp_lines), std::ref(faceDetector), std::ref(fp));
  }

  for(auto &ithread: tmp_threads) {
    ithread.join();
  }

Findings tmp_lines becomes garbled ,,

The reason: tmp_lines is a local variable, at the end of a cycle has been destructed, but the object is still referenced to access the memory area, so garbled

 

 

 

Guess you like

Origin blog.csdn.net/loubiao9212/article/details/84993960