0 Star 0 Fork 0

TRH/生成中间代码的编译器

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
cache_thread.h 2.31 KB
一键复制 编辑 原始数据 按行查看 历史
#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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/trhdq/MY_IDE.git
git@gitee.com:trhdq/MY_IDE.git
trhdq
MY_IDE
生成中间代码的编译器
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385