ex6.c 687 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <errno.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <pthread.h>
  5. #include <unistd.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. setvbuf (stdout, NULL, _IONBF, 0);
  16. for (count = 0; count < 2000; ++count)
  17. {
  18. pthread_t thread;
  19. int status;
  20. status = pthread_create (&thread, NULL, test_thread, NULL);
  21. if (status != 0)
  22. {
  23. printf ("status = %d, count = %lu: %s\n", status, count,
  24. strerror (errno));
  25. return 1;
  26. }
  27. else
  28. {
  29. printf ("count = %lu\n", count);
  30. }
  31. /* pthread_detach (thread); */
  32. pthread_join (thread, NULL);
  33. usleep (10);
  34. }
  35. return 0;
  36. }