/
Zero_Fly
/
parall
Обзор
Документация
Войти
/
Zero_Fly
/
parall
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/parallel-executor/App.h
63 строки
2 KB
akulyanin
add random string
22 янв 2025, 15:33
22 янв 2025, 15:33
4c9eefb
Код
Авторство
О чём код?
#include"deviceA.h" #include"deviceB.h" #include"EventQueue.h" #include"DeviceEvent.h" #include<iostream> using namespace std; class App { public: App(size_t _dataCountA, size_t _dataCountB, int _lifeTimeA, int _lifeTimeB) : dataCountA(_dataCountA) , dataCountB(_dataCountB) , queue_(EventQueue()) { this->deviceA = make_shared<DeviceA>(_lifeTimeA, new ReadA()); this->deviceB = make_shared<DeviceB>(_lifeTimeB, new ReadB()); } ~App(); void run(){ thread threardA(&App::read, this, deviceA, dataCountA); thread threardB(&App::read, this, deviceB, dataCountB); threardA.join(); threardB.join(); while (true) { auto event = queue_.pop(chrono::seconds(5)); if(event){ cout<<event->toString()<<endl; } else{ cout<<"No event in 5 second."<<endl; return; } } }; protected: void read(shared_ptr<Device> dev, int dataCount){ shared_ptr<DeviceEvent> event = make_shared<StartWork>(dev); queue_.push(event); int i = 0; for (; i<dataCount; i++){ event = make_shared<DataEvent>(dev); queue_.push(event); if (dev->getLifeTime() == 0) break; } event = make_shared<WorkDoneEvent>(dev); queue_.push(event); } private: shared_ptr<Device> deviceA; shared_ptr<Device> deviceB; EventQueue queue_; int dataCountA = 0; int dataCountB = 0; };