Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. class Thread{
  2.     protected:
  3.     pthread_t thread;
  4.  
  5.     public:
  6.     void start();
  7.     void run();
  8.     static void* runWrapper(void *threadClass){
  9.         ((Thread*)threadClass)->run();
  10.     };
  11.     void stop();
  12. };
  13.  
  14. void Thread::run(){
  15.     printf("lol");
  16. }
  17.  
  18. void Thread::start(){
  19.     long t = 0;
  20.     int rc;
  21.  
  22.     rc = pthread_create(&thread, NULL, runWrapper, (void*)this);
  23.     if (rc){
  24.          printf("ERROR; return code from pthread_create() is %d\n", rc);
  25.          exit(-1);
  26.     }
  27. }
  28.  
  29. void Thread::stop(){
  30.     pthread_exit(NULL);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement