#include <iostream>
#include <boost/thread.hpp>
using namespace std;
struct A
{
void operator()()
{
sleep(1);
cout << "Hello from thread" << endl;
}
boost::thread t;
void start()
{
t = boost::thread(boost::ref(*this));
}
};
struct Controller : public A
{
};
int main()
{
Controller controller;
controller.start();
cout << "Thread started" << endl;
controller.t.join();
}
// $ g++ test.cpp -lboost_thread -pthread
// $ ./a.out
// Thread started
// Hello from thread
// $