Advertisement
Guest User

Untitled

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