我正在尝试编写一个命令行服务器,它将从串行端口接收信息,解析它,并将其记录在内部对象中.
然后,根据客户端的请求,服务器将返回所请求的信息.
我想要做的是将接收器和解析器部件放在一个单独的线程中,以使服务器一起运行,而不是干扰数据收集.
#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
Run Code Online (Sandbox Code Playgroud)