test02.c 604 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include "unpthread.h"
  2. void *
  3. myfunc(void *ptr)
  4. {
  5. int val;
  6. printf("thread ID of myfunc: %d\n", pthread_self());
  7. val = *((int *) ptr);
  8. printf("val = %d\n", val);
  9. sleep(10);
  10. val = *((int *) ptr);
  11. printf("val = %d\n", val);
  12. }
  13. int
  14. main(int argc, char **argv)
  15. {
  16. pthread_t tid;
  17. int n, val;
  18. printf("thread ID of main: %d\n", pthread_self());
  19. /* Let's verify that the value pointed to the thread's argument is
  20. modifiable */
  21. val = 123;
  22. if ( (n = pthread_create(&tid, NULL, myfunc, &val)) != 0)
  23. errno = n, err_sys("pthread_create error");
  24. sleep(5);
  25. val = 789;
  26. sleep(20);
  27. exit(0);
  28. }