Hi, I've got this test case here that compiles with g++ theFile.cc -lboost_thread. When running the program it seems to be hanging at the join command. I'm not exactly sure why. It's like the interrupt_point() function isn't getting the join request from the main thread.
#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;
}
thanks for reading.
EDIT: also, if you remove the while loop the program exits cleanly... boost version 1.39.0