g ++ theFile.cc -lboost_thread로 컴파일하는 테스트 케이스가 있습니다. 프로그램을 실행할 때 join 명령에 매달려있는 것처럼 보입니다. 왜 그랬는지 정확히 모르겠습니다. 그것은 interrupt_point() 함수가 주 스레드로부터 조인 요청을받지 못하는 것과 같습니다.스레드를 높이고 조인
#include <iostream>
#include <stdio.h>
#include <signal.h>
#include <fstream>
#include <boost/thread.hpp>
using namespace std;
//////////////////////////////////
class SerialnIMU {
public:
~SerialnIMU();
void start();
void stop();
private:
boost::thread readThread;
class SerialReader {
public:
void operator()();
private:
};
};
////////////////////////////////
SerialnIMU::~SerialnIMU() {
stop();
}
void SerialnIMU::start() {
readThread = boost::thread(SerialReader());
cout<<"Created: "<<readThread.get_id()<<endl;
}
void SerialnIMU::stop() {
cout<<"Join: "<<readThread.get_id()<<endl;
cout<<"Joining serial thread..."<<endl;
readThread.join();
cout<<"Done."<<endl;
}
//////////////////////serial thread//////////////////
void SerialnIMU::SerialReader::operator()() {
cout<<"Serial reading thread started..."<<endl;
try {
while(true) {
boost::this_thread::interruption_point();
}
} catch(...) {
cout<<"exception was thrown."<<endl;
}
cout<<"Serial reading thread stopped."<<endl;
}
int main(int argc, char **argv) {
SerialnIMU imu;
imu.start();
imu.stop();
return 0;
}
감사합니다.
편집 : 당신은 while 루프를 제거하면 또한, 프로그램은 정상적으로 종료 ... 부스트 버전 1.39.0
우리가 중단 예외를 포착하지 않는다면 멈출 것입니까? –