Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include "thread.h"
  2. #define NUM_THREADS     10
  3.  
  4. using namespace std;
  5.  
  6. int x = 10;
  7. /*
  8. void *PrintHello(void *threadid)
  9. {
  10.    long tid;
  11.    tid = (long)threadid;
  12.    printf("Hello World! It's me, thread #%ld!\n", tid);
  13.    ++x;
  14.    pthread_exit(NULL);
  15. }
  16.  
  17. int main (int argc, char *argv[])
  18. {
  19.    pthread_t threads[NUM_THREADS];
  20.    int rc;
  21.    long t;
  22.    for(t=0; t<NUM_THREADS; t++){
  23.       printf("In main: creating thread %ld\n", t);
  24.       rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
  25.       if (rc){
  26.          printf("ERROR; return code from pthread_create() is %d\n", rc);
  27.          //exit(-1);
  28.       }
  29.    }
  30.    cout << x << endl;
  31.    pthread_exit(NULL);
  32. }
  33. */
  34.  
  35. void* foo(void *threadId){
  36.     for(int i=0; i<200; ++i)
  37.         printf("lol");
  38.     pthread_exit(NULL);
  39. }
  40. void* foo2(void *threadId){
  41.     for(int i=0; i<200; ++i)
  42.         printf("nab");
  43.     pthread_exit(NULL);
  44. }
  45. int main(){
  46.     Thread t1, t2;
  47.     t1.start();
  48.     t2.start();
  49.     t1.stop();
  50.     t2.stop();
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement