From Abrupt Prairie Dog, 3 Years ago, written in Plain Text.
Embed
">
A PHP Error was encountered
Severity: Notice
Message: Trying to access array offset on value of type bool
Filename: view/view.php
Line Number: 65
and
Re: elo
#include<iostream>
#include<thread>
#include<string>
#include<ctime>
#include<mutex>
#include<queue>
#include<fstream>
#include<sstream>
using namespace std;
string addString() {
std::string temp;
temp.resize(10);
for (int i = 0; i < 10; i++) {
temp[i] = rand() % ('z' - 'a' + 1) + 'a';
}
return temp;
}
void producent(bool &on , queue<string> &vec, const int queueLenght) {
while (on)
{
string tmp = addString();
if (vec.size() < queueLenght){
vec.push(tmp);
cerr << tmp << endl;
}
else
cerr << "Obiekt o ID " << tmp << " nie trafil do kolejki" << endl;
this_thread::sleep_for(chrono::seconds(1));
}
}
void consument(bool &on, queue<string> &vec, const int queueLenght, ofstream &file) {
while (on)
{
if (!vec.empty()) {
if (file.is_open()){
file << vec.front() << endl;
cerr << "Zapisano element o ID : " << vec.front() << endl;
vec.pop();
this_thread::sleep_for(chrono::seconds(1));
}
}
}
file.close();
}
int main() {
srand(time(NULL));
bool isOn = true;
const int queueLenght = 10;
int noCons = 2;
int noProd = 2;
queue<string> bufor;
vector<thread> thread_vec_c;
vector<thread> thread_vec_p;
for (int i = 0; i < noCons; i++) {
ofstream file;
thread::id ID = this_thread::get_id();
stringstream ss;
ss << ID;
string mystring = ss.str();
string mystringtxt = mystring + ".txt";
file.open(mystringtxt);
thread tmp(consument , ref(isOn), ref(bufor), queueLenght, ref(file));
thread_vec_c.push_back(move(tmp));
}
for (int i = 0; i < noProd; i++) {
thread tmp(producent, ref(isOn), ref(bufor), queueLenght);
thread_vec_p.push_back(move(tmp));
}
getchar();
isOn = false;
for (auto &t : thread_vec_p) {
t.join();
}
for (auto &t : thread_vec_c) {
t.join();
}
system("pause");
return 0;
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}