Guest User

Untitled

a guest
Apr 26th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1.  
  2. #include <pthread.h>
  3. #include <stdio.h>
  4.  
  5. /* This is our thread function. It is like main(), but for a thread*/
  6. void *threadFunc(void *arg)
  7. {
  8. int *str;
  9. int i = 0;
  10.  
  11. str=(char*)arg;
  12.  
  13. while(i < 110 )
  14. {
  15. usleep(1);
  16. printf("threadFunc says: %s\n",str);
  17. ++i;
  18. }
  19.  
  20. return NULL;
  21. }
  22.  
  23. int main(void)
  24. {
  25. pthread_t pth; // this is our thread identifier
  26. int i = 0;
  27. int a = 0;
  28.  
  29. for(a = 0; a < 255; a++){
  30. pthread_create(&pth,NULL,threadFunc,a);
  31. }
  32. while(i < 100)
  33. {
  34. usleep(1);
  35. printf("main is running...\n");
  36. ++i;
  37. }
  38.  
  39. printf("main waiting for thread to terminate...\n");
  40. pthread_join(pth,NULL);
  41.  
  42. return 0;
  43. }
Add Comment
Please, Sign In to add comment