xref: /nrf52832-nimble/rt-thread/examples/libc/ex6.c (revision 104654410c56c573564690304ae786df310c91fc)
1 #include <errno.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <pthread.h>
5 #include <unistd.h>
6 
7 #define usleep rt_thread_sleep
8 
test_thread(void * v_param)9 static void *test_thread(void *v_param) {
10 	return NULL;
11 }
12 
libc_ex6(void)13 int libc_ex6(void) {
14 	unsigned long count;
15 
16 	setvbuf(stdout, NULL, _IONBF, 0);
17 
18 	for (count = 0; count < 2000; ++count) {
19 		pthread_t thread;
20 		int status;
21 
22 		status = pthread_create(&thread, NULL, test_thread, NULL);
23 		if (status != 0) {
24 			printf("status = %d, count = %lu: %s\n", status, count, strerror(
25 					errno));
26 			return 1;
27 		} else {
28 			printf("count = %lu\n", count);
29 		}
30 		/* pthread_detach (thread); */
31 		pthread_join(thread, NULL);
32 		usleep(10);
33 	}
34 	return 0;
35 }
36 #include <finsh.h>
37 FINSH_FUNCTION_EXPORT(libc_ex6, example 6 for libc);
38