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 <future>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
@ -129,17 +130,21 @@ int main(int argc, char *argv[])
|
||||||
search_settings.context = opts.context;
|
search_settings.context = opts.context;
|
||||||
|
|
||||||
vector<vector<search::match>> matches_all;
|
vector<vector<search::match>> matches_all;
|
||||||
|
std::mutex mutex_matches_all;
|
||||||
vector<std::future<int>> futurepool;
|
vector<std::future<int>> futurepool;
|
||||||
|
|
||||||
auto search_file{
|
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)
|
for (const auto ®ex : opts.regexp)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
matches_all.emplace_back(
|
auto matches{
|
||||||
search::search(filepath, regex, search_settings));
|
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)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue