问题遇到的现象和发生背景
问
题相关代码,请勿粘贴截图
有问题可以问哈,一共建3个文件,如下:
main.cpp文件
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <thread>
#include "cmdLine.h"
#include "mutlithread.h"
int main(int argc, char *argv[])
{
std::string inputPath = "/media/add7/E/testData/testThreads/";
std::vector<std::string> fileNameList;
for(std::size_t i = 0; i < 20; ++i)
{
std::stringstream ss;
ss << i;
std::string s;
ss >> s;
std::string tempPath = inputPath + "/" + s + ".txt";
fileNameList.push_back(tempPath);
}
MutliThread myThread;
myThread.initialization("/media/add7/E/testData/testThreads/out/");
while(true)
{
if(MutliThread::writeFinish && MutliThread::showFinish)
break;
std::thread th1(MutliThread::readFile, &fileNameList, &myThread);
std::thread th2(MutliThread::showFile);
std::thread th3(MutliThread::writeFile, &myThread);
std::cout << "join th1" << std::endl;
th1.join();
std::cout << "join th2" << std::endl;
th2.join();
std::cout << "join th3" << std::endl;
th3.join();
}
std::cout << "threads exit !" << std::endl;
return 1;
}