All pastes #486475 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-05-13 22:15 UTC
rendered paste body
#include <pthread.h>

class Thread
{
  public:
  	class pt_error{};
  	virtual void run();
  	virtual void stop();
  	virtual bool running() const;
  	virtual void join();
  	virtual void setup();
  	virtual ~Thread();
  	static void sleep(unsigned long msecs);
  	void Arg(void* a){arg_ =a;};
  	void* Arg(){return arg_;};
  protected:
  	void start(void*);
  	virtual void *main(void *)=0;
  private:
  	static void static_run(void* arg);
  	Thread(const Thread&);
  	Thread& operator=(const Thread&);
  	pthread_t tid;
  	void * arg_;
 };
 		
/*static */
void Thread::static_run(void* pthis)
{
   ((Thread*)pthis)->run();
}
void Thread::run()
{
	setup();
	pthread_create(&tid,NULL,Thread::main,arg_);
		
}