ex6.c 760 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <errno.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <pthread.h>
  5. #include <time.h>
  6. static void *
  7. test_thread (void *v_param)
  8. {
  9. return NULL;
  10. }
  11. int
  12. main (void)
  13. {
  14. unsigned long count;
  15. struct timespec ts;
  16. ts.tv_sec = 0;
  17. ts.tv_nsec = 10 * 1000;
  18. setvbuf (stdout, NULL, _IONBF, 0);
  19. for (count = 0; count < 2000; ++count)
  20. {
  21. pthread_t thread;
  22. int status;
  23. status = pthread_create (&thread, NULL, test_thread, NULL);
  24. if (status != 0)
  25. {
  26. printf ("status = %d, count = %lu: %s\n", status, count,
  27. strerror (errno));
  28. return 1;
  29. }
  30. else
  31. {
  32. printf ("count = %lu\n", count);
  33. }
  34. /* pthread_detach (thread); */
  35. pthread_join (thread, NULL);
  36. nanosleep (&ts, NULL);
  37. }
  38. return 0;
  39. }