ex6.c 1019 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. */
  9. #include <sys/errno.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <pthread.h>
  13. #include <unistd.h>
  14. #define usleep rt_thread_delay
  15. static void *test_thread(void *v_param) {
  16. return NULL;
  17. }
  18. int libc_ex6(void) {
  19. unsigned long count;
  20. setvbuf(stdout, NULL, _IONBF, 0);
  21. for (count = 0; count < 2000; ++count) {
  22. pthread_t thread;
  23. int status;
  24. status = pthread_create(&thread, NULL, test_thread, NULL);
  25. if (status != 0) {
  26. printf("status = %d, count = %lu: %s\n", status, count, strerror(
  27. errno));
  28. return 1;
  29. } else {
  30. printf("count = %lu\n", count);
  31. }
  32. /* pthread_detach (thread); */
  33. pthread_join(thread, NULL);
  34. usleep(10);
  35. }
  36. return 0;
  37. }
  38. #include <finsh.h>
  39. FINSH_FUNCTION_EXPORT(libc_ex6, example 6 for libc);