代码拉取完成,页面将自动刷新
#include <iostream>
using namespace std;
#include <fstream>
#include <string>
#include <thread>
#include <mutex>
#ifndef __CACHETHREAD__
#define __CACHETHREAD__
#include "identify.h"
#include "hexadecimal.h"
#define filename "./cffx.txt"
#define CACHE_SIZE 60
bool has_finish_read = false;
mutex READ_CACHE[2];
mutex READ_FILE;
void read_cache(int cache_number, string &cache, ifstream &fin){
//while(! has_finish_read){
READ_CACHE[cache_number].lock();
READ_FILE.lock();
if(has_finish_read){
READ_FILE.unlock();
READ_CACHE[cache_number].unlock();
return;
}
cache = "";
char temp_ch;
cout<<"child thread:"<<endl;
do
{
temp_ch=fin.get(); //循环读取文件中的字符
cout<<temp_ch;
cache += temp_ch; //将读到的字符存入字符数组
}while( cache.length() < CACHE_SIZE && !fin.eof() ); //判断是否到文件末尾了
if(cache.length() < CACHE_SIZE || fin.eof()){
has_finish_read = true;
}
cout<<endl;
READ_FILE.unlock();
READ_CACHE[cache_number].unlock();
//}
return;
}
void get_token(ifstream &fin){
string cache[2] = "";
int time = 0;
int cache_choose = 0;
int read_index = 0;
int result = 0;
thread save_cache[2];
save_cache[0] = thread(read_cache, cache_choose, ref(cache[0]), ref(fin));
//save_cache[1] = thread(read_cache, ref(cache[1]), ref(fin));
save_cache[0].join();
do{
read_index = 0;
save_cache[!cache_choose] = thread(read_cache, !cache_choose, ref(cache[!cache_choose]), ref(fin));
save_cache[!cache_choose].detach();
READ_CACHE[cache_choose].lock();
if(result == 716){
cout<<"=================="<<endl<<"continue token:"<<token_buffer<<endl;
cache[cache_choose] = token_buffer + cache[cache_choose];
cout<<"=================="<<endl<<"current token:"<<cache[cache_choose]<<endl;
}
do{
result = scan(cache[cache_choose], read_index);
if(result == 9999){
cout<<"ERROR"<<endl;
}
else{
cout<<"result:"<<result<<endl;
}
cout<<"read_index:"<<read_index<<","<<(int)cache[cache_choose][read_index]<<endl;
cout<<"----------------------"<<endl;
//cache_choose = !cache_choose;
}while( result != END && result != 716);
cout<<"=================="<<endl<<"end token:"<<token_buffer<<endl;
cache_choose = !cache_choose;
READ_CACHE[!cache_choose].unlock();
time ++;
}while(result != END);
cout<<endl<<"time:"<<time<<endl;
}
#endif
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。