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 
15 #define usleep rt_thread_delay
16 
test_thread(void * v_param)17 static void *test_thread(void *v_param) {
18     return NULL;
19 }
20 
libc_ex6(void)21 int libc_ex6(void) {
22     unsigned long count;
23 
24     setvbuf(stdout, NULL, _IONBF, 0);
25 
26     for (count = 0; count < 2000; ++count) {
27         pthread_t thread;
28         int status;
29 
30         status = pthread_create(&thread, NULL, test_thread, NULL);
31         if (status != 0) {
32             printf("status = %d, count = %lu: %s\n", status, count, strerror(
33                     errno));
34             return 1;
35         } else {
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);
46