All pastes #565845 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-06-14 05:41 UTC
rendered paste body
template <class T>
class MyThread : public QThread{
   QMutex m;
   QWaitCondition cond;
   T *object;
   MyThread() : object(NULL) {}
   void run()
   {
      m.lock();
      object = new T();
      cond.wakeOne();
      m.unlock();
   }
   T *init()
   {
      start();
      m.lock();
      while (!object)
         cond.wait(&m);
      m.unlock();
      return object;
   }
public:
   static T *create()
   {
      MyThread *thread = new MyThread;
      return thread->init();
   }
};