Advertisement
Guest User

p6

a guest
Jan 23rd, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <pthread.h>
  3. #include <sys/neutrino.h>
  4. pthread_t thread_id1;
  5. pthread_t thread_id2;
  6. void * long_thread1(void *notused)
  7. {
  8. int n;
  9. for(n=0; n<5; n++)
  10. {
  11. printf("This is first thread, TID %d, N repeat %d \n", thread_id1, n);
  12. sleep(2);
  13. }
  14. }
  15. void * long_thread2(void *notused)
  16. {
  17. int m;
  18. for(m=0; m<5; m++)
  19. {printf("This is second thread, TID %d, N repeat %d \n", thread_id2, m);
  20. sleep(1);
  21. }
  22. }
  23. int main(void)
  24. {
  25. printf("Parent PID = %d\n", getpid());
  26. pthread_create(&thread_id1, NULL, long_thread1, NULL);
  27. pthread_create(&thread_id2, NULL, long_thread2, NULL);
  28. sleep(20);
  29. return(1);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement