void run () { while (!queue.empty()) { std::shared_ptr<Runnable*> runnable = queue.wait_and_pop(); Runnable *executable =*runnable.get(); std::thread t1(&Runnable::operator(),executable); threads.push_back(std::move(t1)); } }
void data_preparation_thread() { while(more_data_to_prepare()) { data_chunk const data=prepare_data(); data_queue.push(data); } }
void send_thread(){ int i = 0; while(i<50){ std::string s; squeue.wait_and_pop(s); std::cout<<s<<std::endl; i++; } }
void write_thread(){ int i = 0; while(i <50 ){ std::string const data = std::string("xxxxxx"); squeue.push(data); i++; } }
void data_processing_thread() { while(true) { data_chunk data; data_queue.wait_and_pop(data); process(data); if(is_last_chunk(data)) break; } }
//main thread void RealTimeDataProcessor::AppendRealTimeData(TickWrapper& info){ //(in)front-------------back(out) // if m_strategy == nullptr, that means RealTimeDataProcessor is in data-recording mode if (m_strategy){ #ifdef UseKDataToInvoke bool triggered = m_strategy->tryInvoke(m_DataSeq, m_KDataVec, m_TickSet60, info); #else bool triggered = m_strategy->tryInvoke(m_DataSeq, info); #endif if (triggered){ Order ord; //for now, only permit order_queue has one item. if (order_queue.empty() && m_strategy->generateOrder(ord)){ order_queue.push(ord); } } } m_DataSeq.push_front(info); //construct 1-minutes k-line intermediate data if (m_TickSet60.empty()){ m_TickSet60.push_back(info); } else{ if (CommonUtils::InSameMinute(info.Time(), m_TickSet60.front().Time())){ m_TickSet60.push_back(info); } else{ // the comming tick data is in next minutes KData k1m(m_TickSet60, 60); m_KDataVec.push_back(k1m); m_TickSet60.clear(); } } #ifdef SHOW_PROGRESS spdlog::get("console")->info() << "> Data queue size :" << m_DataSeq.size(); #endif }
inline void doSomething2() { queue.push(&doOper2); }
inline void doSomething() { queue.push(&doOper); }