All pastes #563982 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-06-13 11:58 UTC
rendered paste body
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

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

using namespace std;

namespace ldap_proxy {

class Thread { 
 public: 
     Thread(); 
     virtual ~Thread(); 
     void start();
	 void wait();
     virtual void run() {}; 
 private: 
     pthread_t thread; 
}; 

}

extern "C" {  
  static void*  do_call_run(void* arg) 
  { 
     if (arg) { 
         ldap_proxy::Thread* t = (ldap_proxy::Thread*)arg; 
         t->run(); 
     } 
     return 0; 
  } 
} 

namespace ldap_proxy {
 
Thread::Thread() 
{ 
     // empty 
} 
 
Thread::~Thread() 
{ 
     pthread_join(thread,0); 
} 
 
void Thread::start() 
{ 
     pthread_create(&thread,0,do_call_run,this); 
}

void Thread::wait()
{
	 pthread_join(thread,0);
}

}