Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <pthread.h>
  2. #include <stdio.h>
  3.  
  4. int x;
  5. pthread_mutex_t mutex;
  6.  
  7. void *PrintHello(void *arg){
  8. pthread_mutex_lock(&mutex);
  9. int x = (int) arg;
  10. x++;
  11. printf("%i\n",x);
  12. pthread_mutex_unlock(&mutex);
  13. pthread_exit(NULL);
  14. }
  15.  
  16. int main(int argc, char **argv){
  17. pthread_t threadc[200];
  18. long int arg = 123;
  19. pthread_mutex_init (&mutex,NULL);
  20. for(int i=0;i<200;i++)
  21. pthread_create(&threadc[i],NULL,PrintHello,(void *)x);
  22. for(int j=0;j<200;j++)
  23. pthread_join(threadc[j],NULL);
  24. pthread_mutex_destroy(&mutex);
  25. pthread_exit(NULL);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement