diff --git a/src/main.cpp b/src/main.cpp index b59fea8..adb8bcf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -129,17 +130,21 @@ int main(int argc, char *argv[]) search_settings.context = opts.context; vector> matches_all; + std::mutex mutex_matches_all; vector> futurepool; auto search_file{ - [&opts, &matches_all, &search_settings](fs::path filepath) + [&opts, &matches_all, &mutex_matches_all, + &search_settings](const fs::path &filepath) { for (const auto ®ex : opts.regexp) { try { - matches_all.emplace_back( - search::search(filepath, regex, search_settings)); + auto matches{ + search::search(filepath, regex, search_settings)}; + std::lock_guard guard(mutex_matches_all); + matches_all.emplace_back(matches); } catch (const std::exception &e) {