Próbuję zaprogramować serwer wiersza poleceń, który odbierałby informacje z portu szeregowego, analizował go i zapisywał w obiekcie wewnętrznym.C++ std :: thread funkcji elementu
Następnie, na żądanie klienta, serwer zwróci żądane informacje.
Co chcę zrobić, to umieścić odbiornik & w oddzielnym wątku, aby serwer działał obok, nie ingerując w zbieranie danych.
#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
Czy można skompilować 'public void completeProcess() {..'? – Deqing
Możliwy duplikat [Rozpocznij wątek z funkcją członka] (http://stackoverflow.com/questions/10673585/start-thread-with-member-function) –