#include <pthread.h>
#include <iostream>

class Thread
{
public:
  Thread() {}

  void start() {
    pthread_start(&m_tid, 0, helper, this);
  }

  void waitTillFinished() {
    pthread_join(m_tid, 0);
  }

private:
  void run() {
    std::cout << "thread is running." << std::endl;  // not thread-safe!
  }

  static void* helper(void* arg) {
    Thread* t = static_cast<Thread*>(arg);
    t->run();
    pthread_exit(0);
    return 0;
  }

  pthread_t m_tid;
};

int main()
{
  Thread thread;
  thread.start();
  thread.waitTillFinished();  // this is not typically done this way
}
