1. #include <iostream>
  2. #include <boost/thread.hpp>
  3. using namespace std;
  4.  
  5. struct A
  6. {
  7.   void operator()()
  8.   {
  9.     sleep(1);
  10.     cout << "Hello from thread" << endl;
  11.   }
  12.  
  13.   boost::thread t;
  14.  
  15.   void start()
  16.   {
  17.     t = boost::thread(boost::ref(*this));
  18.   }
  19. };
  20.  
  21. struct Controller : public A
  22. {
  23. };
  24.  
  25. int main()
  26. {
  27.   Controller controller;
  28.   controller.start();
  29.   cout << "Thread started" << endl;
  30.   controller.t.join();
  31. }
  32.  
  33.  
  34. //  $ g++ test.cpp -lboost_thread -pthread
  35. //  $ ./a.out
  36. //  Thread started
  37. //  Hello from thread
  38. //  $