Вот исправленный вариант.
Вы передавали один in на всех и попадали в гонку/deadlock.
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <vector>
#include <deque>
#include <map>
#include <thread>
#include <mutex>
std::mutex mutex;
std::string files[4] =
{
"file1.txt",
"file2.txt",
"file3.txt",
"file4.txt"
};
void pipeline(std::string &in, std::vector<std::string> &str)
{
std::lock_guard<std::mutex> lock(mutex);
std::ifstream file;
file.open(in);
while (!file.eof())
{
std::string temp;
std::getline(file, temp);
str.push_back(temp);
}
std::cout << in << " finished" << std::endl;
file.close();
}
int main()
{
std::string string;
std::vector<std::string> str;
std::map<std::string, std::size_t> freq;
std::deque<std::thread> pool;
std::ofstream out("out.txt");
for (std::size_t i = 0; i < 4; i++)
{
pool.push_back(std::thread(pipeline, std::ref(files[i]), std::ref(str)));
}
while (pool.size())
{
pool.front().join();
pool.pop_front();
}
out << str.size();
std::cout << str.size();
std::cin.get();
return 0;
}