Don't write to matches_all simultaneously from different threads.
What did I do yesterday?!? 😬 Closes: #6
This commit is contained in:
parent
38bf9be948
commit
8d5565a72c
11
src/main.cpp
11
src/main.cpp
|
@ -33,6 +33,7 @@
|
|||
#include <future>
|
||||
#include <iostream>
|
||||
#include <locale>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
|
@ -129,17 +130,21 @@ int main(int argc, char *argv[])
|
|||
search_settings.context = opts.context;
|
||||
|
||||
vector<vector<search::match>> matches_all;
|
||||
std::mutex mutex_matches_all;
|
||||
vector<std::future<int>> 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<std::mutex> guard(mutex_matches_all);
|
||||
matches_all.emplace_back(matches);
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user