ex6.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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_sleep
  15. static void *test_thread(void *v_param)
  16. {
  17. return NULL;
  18. }
  19. int libc_ex6(void)
  20. {
  21. unsigned long count;
  22. setvbuf(stdout, NULL, _IONBF, 0);
  23. for (count = 0; count < 2000; ++count)
  24. {
  25. pthread_t thread;
  26. int status;
  27. status = pthread_create(&thread, NULL, test_thread, NULL);
  28. if (status != 0)
  29. {
  30. printf("status = %d, count = %lu: %s\n", status, count, strerror(
  31. errno));
  32. return 1;
  33. }
  34. else
  35. {
  36. printf("count = %lu\n", count);
  37. }
  38. /* pthread_detach (thread); */
  39. pthread_join(thread, NULL);
  40. usleep(10);
  41. }
  42. return 0;
  43. }
  44. #include <finsh.h>
  45. FINSH_FUNCTION_EXPORT(libc_ex6, example 6 for libc);