我試圖編寫一個命令行服務器,它將從串行端口接收信息,解析它,並將其記錄在內部對象中。C++ std ::成員函數的線程
然後根據客戶端的請求,服務器將返回請求的信息。
我想要做的是將接收器&分析器部件放在一個單獨的線程中,以便讓服務器沿着一側運行,而不會干擾數據收集。
#include <iostream>
#include <thread>
class exampleClass{
std::thread *processThread;
public void completeProcess(){
while(1){
processStep1();
if (verification()){processStep2()}
}
};
void processStep1(){...};
void processStep2(){...};
bool verification(){...};
void runThreaded();
} // End example class definition
// The idea being that this thread runs independently
// until I call the object's destructor
exampleClass::runThreaded(){
std::thread processThread(&exampleClass::completeProcess, this);
} // Unfortunately The program ends up crashing here with CIGARET
是否可以編譯public void completeProcess(){..'? – Deqing
可能重複[啓動線程與成員函數](http://stackoverflow.com/questions/10673585/start-thread-with-member-function) –